요즘 회사용 linux PC(ubuntu 8.04 hardy)에 Screenlets(http://www.screenlets.org/index.php/Home)를 깔아 쓰고 있습니다. 그 중에 보면 Slideshow가 있는데요. Slideshow의 기능 중에 Flickr의 공개된 일부 그림들을 볼 수가 있는데요. 이게 URL이 정해져 있어서 좀 답답합니다. 그래서 이걸 좀 다른 Flickr도 쓸 수 있게 바꿔보았습니다.

[Screenlets 화면]
/usr/share/screenlets/Slideshow/SlideshowScreenlet.py를 다음과 같이 수정하면 됩니다. 혹시 python-BeautifulSoup이나 python-image-library가 안 깔려 있다면 설치해야 합니다. 아래 와 같이 수정하면 Flickr로 설정을 변경할 경우, 전지현+김태희 그림이 나오도록 세팅되어있구요. 이걸 바꾸거나 추가하고 싶으면, 파일 제일 앞부분의 FLICKR_URLS = [ ... ] 에 url string을 추가하면 됩니다.
우선 파일 앞부분에 다음을 추가합니다.
그리고 파일 중간 부분의 fetch_image 함수를 다음과 같이 수정합니다. 즉, fetch_image 함수에서 if self.engine1=='Flickr': 부분부터 imageget = urlopen(realimage) 앞까지 쭈욱 갖다 붙이시면 됩니다. 아, 물론 이 사이에 있던 기존 코드는 살짝 주석처리해 주셔야됩니다.
ps. 현재는 flickr 검색페이지 결과만 파싱 가능함.
ps2. 괜찮은 연예인 flickr url(or 검색어) 찾으면 댓글로 좀 알려주세요~

[Screenlets 화면]
/usr/share/screenlets/Slideshow/SlideshowScreenlet.py를 다음과 같이 수정하면 됩니다. 혹시 python-BeautifulSoup이나 python-image-library가 안 깔려 있다면 설치해야 합니다. 아래 와 같이 수정하면 Flickr로 설정을 변경할 경우, 전지현+김태희 그림이 나오도록 세팅되어있구요. 이걸 바꾸거나 추가하고 싶으면, 파일 제일 앞부분의 FLICKR_URLS = [ ... ] 에 url string을 추가하면 됩니다.
우선 파일 앞부분에 다음을 추가합니다.
FLICKR_URLS = [
'http://www.flickr.com/search/?s=int&q=%EC%A0%84%EC%A7%80%ED%98%84&m=text',
'http://www.flickr.com/search/?s=int&q=%EA%B9%80%ED%83%9C%ED%9D%AC&m=text'
]
from BeautifulSoup import BeautifulSoup
import re
'http://www.flickr.com/search/?s=int&q=%EC%A0%84%EC%A7%80%ED%98%84&m=text',
'http://www.flickr.com/search/?s=int&q=%EA%B9%80%ED%83%9C%ED%9D%AC&m=text'
]
from BeautifulSoup import BeautifulSoup
import re
그리고 파일 중간 부분의 fetch_image 함수를 다음과 같이 수정합니다. 즉, fetch_image 함수에서 if self.engine1=='Flickr': 부분부터 imageget = urlopen(realimage) 앞까지 쭈욱 갖다 붙이시면 됩니다. 아, 물론 이 사이에 있던 기존 코드는 살짝 주석처리해 주셔야됩니다.
def fetch_image(self):
...
if self.engine1 == 'Flickr':
#appended by dsp.shin
source = urlopen( random.choice( FLICKR_URLS) )
sourcetxt = source.read()
sources = []
reals = []
rPhoto = re.compile('/photos(.*?)')
soup = BeautifulSoup( sourcetxt )
hrefs = soup('a', {'href':rPhoto})
for href in hrefs:
imgs = href('img', {'class':'pc_img'})
if len(imgs)>0:
sources.append( href.get('href') )
reals.append( imgs[0].get('src') )
if len(sources)>0:
index = random.randint(0, len(sources)-1)
sourceimage = str(sources[index])
realimage = str(reals[index])
imageurl = 'http://www.flickr.com' + sourceimage
self.url = imageurl
else:
#not working
realimage = 'http://creativeclass.typepad.com/thecreativityexchange/images/2007/09/19/menatwork.png'
self.url = realimage
#end -- dsp.shin
imageget = urlopen(realimage)
...
...
if self.engine1 == 'Flickr':
#appended by dsp.shin
source = urlopen( random.choice( FLICKR_URLS) )
sourcetxt = source.read()
sources = []
reals = []
rPhoto = re.compile('/photos(.*?)')
soup = BeautifulSoup( sourcetxt )
hrefs = soup('a', {'href':rPhoto})
for href in hrefs:
imgs = href('img', {'class':'pc_img'})
if len(imgs)>0:
sources.append( href.get('href') )
reals.append( imgs[0].get('src') )
if len(sources)>0:
index = random.randint(0, len(sources)-1)
sourceimage = str(sources[index])
realimage = str(reals[index])
imageurl = 'http://www.flickr.com' + sourceimage
self.url = imageurl
else:
#not working
realimage = 'http://creativeclass.typepad.com/thecreativityexchange/images/2007/09/19/menatwork.png'
self.url = realimage
#end -- dsp.shin
imageget = urlopen(realimage)
...
ps. 현재는 flickr 검색페이지 결과만 파싱 가능함.
ps2. 괜찮은 연예인 flickr url(or 검색어) 찾으면 댓글로 좀 알려주세요~