심심해서 재미있으라고 만들어보는 YahooGallery

atie의 이미지

:lol:
HtmlParser 1.5를 사용했습니다.

package pe.atie.yg;

import java.io.BufferedWriter;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;

import org.htmlparser.NodeFilter;
import org.htmlparser.Parser;
import org.htmlparser.filters.AndFilter;
import org.htmlparser.filters.HasChildFilter;
import org.htmlparser.filters.TagNameFilter;
import org.htmlparser.util.NodeList;
import org.htmlparser.util.ParserException;

public class YahooGallery {
	private static final int howMany = 19; //20 Pages = 400 Pics 
	private static StringBuffer sb = new StringBuffer();
	private static String jjhUrl = "http://images.search.yahoo.com/search/images?ei=UTF-8&fr=sfp&p=%EC%A0%84%EC%A7%80%ED%98%84";
	private static Parser parser = new Parser();
	private static NodeList list = new NodeList ();
	private static NodeFilter filter = new AndFilter(new TagNameFilter ("td"), new HasChildFilter (new TagNameFilter ("a")));
	
	private static void makeHtmlHeader() {
		sb.append("<html>\n");
		sb.append("<meta http-equiv='content-type' content='text/html; charset=UTF-8'>\n");
		sb.append("<title>Yahoo Gallery</title>\n");
		sb.append("<body>\n");
	}
	
	private static void makeHtmlTitle() {
		sb.append("<h4>");
		sb.append(jjhUrl);
		sb.append("</h4>\n");
	}
	
	private static void makeHtmlFooter() {
		sb.append("</body>\n");
		sb.append("</html>");
	}
	
	private static void convertImageUrl2Html() throws ParserException {
		list = parser.extractAllNodesThatMatch(filter);
		//System.out.println(list.toHtml());
		sb.append("<table>");
		sb.append(list.toHtml());
		sb.append("'</table>\n");
	}
	
	private static void writeHtmlFile() throws IOException {
		 BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream("JJHDemo.html"), "UTF8"));
		 writer.write(sb.toString());
		 writer.close();
	}

	public static void main(String[] args) {
		try {
			makeHtmlHeader();
			for (int i=0; i<=howMany; i++) {
				String url = jjhUrl + "&imgsz=all&xargs=0&pstart=1&fr=sfp&b=" + Integer.toString(i*20+1);
				System.out.println(url);
				parser.setURL(url);
				makeHtmlTitle();
				convertImageUrl2Html();
			}
			makeHtmlFooter();
			writeHtmlFile();
		} catch (Exception e) {
			System.out.println(e);
		}
	}
}

File attachments: 
Forums: 
atie의 이미지

ㅎ 흐 ㅎ ...UI 만들고 있습니다. (아래에 맛보기 화면)
swt이 리눅스에서는 mozilla를 끌어들일 수 있어서 yahoo에서 이미지 링크만 파싱해서 만들고, html 렌더링은 mozilla가 하는 방법으로 GUI하나 해보고 있습니다.

정작 코딩하는 시간보다 레이아웃하고 아이콘 갖다 넣고 하는게 시간이 더 드는군요.

댓글 첨부 파일: 
첨부파일 크기
Image icon 0바이트

----
I paint objects as I think them, not as I see them.
atie's minipage

1day1의 이미지

SWT 도 applet 처럼 IE,firefox 등에서 사용가능한가요?

F/OSS 가 함께하길..

atie의 이미지

python으로는 처음 코딩을 해 보는거라 구글링해가며 짜집기 해 본 것인데, 커넥션이 리셋되면 대책이 없는 버전이기는 해도 그럭저럭 엄지그림을 슬라이드 쇼 해주기는 합니다. 재미로 보시고 개선 사항을 리플해 주세요.

#!/usr/bin/env python
#ythumbsweb.py
# -*- coding: utf-8 -*-

import glob
import gtk
import gtk.gdk
import gobject
import urllib
from BeautifulSoup import BeautifulSoup

# define variables
thumbs = []

class YThumbs:
    def __init__ (self):
        get_thumbs()
        save_thumbs()   
        self.images = glob.glob("thumbs/*.jpg")
        self.image_index = 0
        self.is_fullscreen =False
        self.w = gtk.Window()
        self.vb = gtk.VBox()
        self.i = gtk.Image()
        self.b = gtk.Button('Fullscreen')
        self.b.connect('clicked',self.toggle_fullscreen_cb)
        self.bb=gtk.HButtonBox()
        self.bb.add(self.b)
        self.qb=gtk.Button(stock=gtk.STOCK_QUIT)
        self.qb.connect('clicked',self.quit)
        self.bb.add(self.qb)
        self.vb.pack_start(self.i,expand=True,fill=True)
        self.vb.pack_start(self.bb,expand=False,fill=False)
        self.set_image_cb()
        self.w.add(self.vb)
        self.w.show_all()
        self.w.connect('delete-event',self.quit)

    def run (self):
        """Run our slideshow"""
        gobject.timeout_add(600,self.set_image_cb)
        gtk.main()

    def quit (self, *args):
        self.w.hide()
        gtk.main_quit()

    def set_image_cb (self, *args):
        """Rotate our image."""
        pb = gtk.gdk.pixbuf_new_from_file(self.images[self.image_index])
        pb=self.scale_image_to_window(pb)
        self.i.set_from_pixbuf(pb)
        self.image_index += 1
        if self.image_index > len(self.images): self.image_index = 0
        return True

    def scale_image_to_window (self,pb):
        """Make pixbuf fit our window"""
        ww,wh = self.w.get_size()
        iw,ih=pb.get_width(),pb.get_height() 
        wratio = float(iw)/ww
        hratio = float(ih)/wh
        if wratio > hratio: ratio = wratio
        else: ratio = hratio
        scaled = pb.scale_simple(pb.get_width()/ratio,
                                 pb.get_height()/ratio,
                                 gtk.gdk.INTERP_BILINEAR)
        return scaled

    def toggle_fullscreen_cb (self,*args):
        if self.is_fullscreen:
            self.w.unfullscreen()
            self.w.set_size_request(*self.is_fullscreen)
            self.is_fullscreen=False
        else:
            self.is_fullscreen=self.w.get_size()
            self.w.fullscreen()
        pb = self.scale_image_to_window(self.i.get_pixbuf())
        self.i.set_from_pixbuf(pb)
        
def get_thumbs():
    URL = "http://kr.image.search.yahoo.com/search/images?b="
    NAME = "&p=%B1%E8%C5%C2%C8%F1"
    TYPE = "&subtype=com&z=imgbox"
    n = 1
    while n <= 61: # 80 images, increade this number if you want more thumbs
        PAGE = str(n)
        stream = urllib.urlopen(URL+PAGE+NAME+TYPE)
        soup = BeautifulSoup(stream)
        for link in soup('img'):
            thumb = link.get('src', '')
            if thumb:
                if "thumb" not in thumb:
                    continue
                thumbs.append(thumb)
                print thumb
        n = n + 20           

def save_thumbs():        
    print "saving thumbs ..."
    n = 1
    for thumb in thumbs:
        u = urllib.urlopen(thumb)
        f = open("thumbs/"+str(n)+".jpg", 'w')
        while 1:
            data = u.read(1024)
            if not data: break
            f.write(data)
        u.close()    
        n = n + 1

if __name__ == '__main__':
    yt = YThumbs()
    yt.run()

----
I paint objects as I think them, not as I see them.
atie's minipage

atie의 이미지

istanbul을 설치해서 더 재미가 있어졌습니다. eclipse에서 pydev으로 위의 python 코드를 작성하고 실행해 본 5초가 안되는 ogg (동영상) 파일입니다.

댓글 첨부 파일: 
첨부파일 크기
파일 0바이트

----
I paint objects as I think them, not as I see them.
atie's minipage

thisrule의 이미지

atie wrote:
istanbul을 설치해서 더 재미가 있어졌습니다. eclipse에서 pydev으로 위의 python 코드를 작성하고 실행해 본 5초가 안되는 ogg (동영상) 파일입니다.

현재 리눅스 파폭(in RH9.0)에서 플러그인이 없다고 하네요.
뭘 설치해야 볼 수 있나요?
atie의 이미지

thisrule wrote:
atie wrote:
istanbul을 설치해서 더 재미가 있어졌습니다. eclipse에서 pydev으로 위의 python 코드를 작성하고 실행해 본 5초가 안되는 ogg (동영상) 파일입니다.

현재 리눅스 파폭(in RH9.0)에서 플러그인이 없다고 하네요.
뭘 설치해야 볼 수 있나요?

mplayer은 1.0pre7이상이 되어야 자체 디코더로 play가 되고, totem이 설치되어 있으면 링크를 복사해서 보실 수가 있을 겁니다.

----
I paint objects as I think them, not as I see them.
atie's minipage

atie의 이미지

정정합니다. mplayer에서는 "Ogg stream 0 is of an unknown type" 이 에러가 나서 play를 할 수 없고, totem-xine이나 vlc로는 볼 수가 있군요. zip 파일을 첨부해 놓습니다.

댓글 첨부 파일: 
첨부파일 크기
Package icon 0바이트

----
I paint objects as I think them, not as I see them.
atie's minipage

atie의 이미지

이스탄불에서 생성되는 ogg 파일이 이상해서인지 우분투 브리지가 이상해서인지 xine 계열 플레이어가 GStreamer을 쓰는 경우에만 정상적으로 play가 되는군요.

참고로, 위의 ogg 파일 링크는 http://bbs.kldp.org/files/ythumbs-istanbul_213.ogg 입니다.

----
I paint objects as I think them, not as I see them.
atie's minipage

댓글 달기

Filtered HTML

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

BBCode

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param>
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

Textile

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • You can use Textile markup to format text.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Markdown

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • Quick Tips:
    • Two or more spaces at a line's end = Line break
    • Double returns = Paragraph
    • *Single asterisks* or _single underscores_ = Emphasis
    • **Double** or __double__ = Strong
    • This is [a link](http://the.link.example.com "The optional title text")
    For complete details on the Markdown syntax, see the Markdown documentation and Markdown Extra documentation for tables, footnotes, and more.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Plain text

  • HTML 태그를 사용할 수 없습니다.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 줄과 단락은 자동으로 분리됩니다.
댓글 첨부 파일
이 댓글에 이미지나 파일을 업로드 합니다.
파일 크기는 8 MB보다 작아야 합니다.
허용할 파일 형식: txt pdf doc xls gif jpg jpeg mp3 png rar zip.
CAPTCHA
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.