updating movieposterdb module

This commit is contained in:
Rolux 2009-07-13 23:12:06 +02:00
parent 4781644eac
commit acb0e3f0e8

View file

@ -3,28 +3,34 @@
import re
from oxlib import cache
from oxlib.cache import getUrlUnicode
from oxlib import findRe
def getPosterUrls(imdbId):
url = 'http://www.movieposterdb.com/movie/%s' % imdbId
posterUrls = []
if cache.exists(url):
posterUrls = parsePage(url)
return posterUrls
def parsePage(url):
posterUrls = []
html = cache.getUrlUnicode(url, timeout=86400)
groups = re.compile('<a href="(http://www.movieposterdb.com/group/.*?)">', re.DOTALL).findall(html)
for group in groups:
posterUrls += parsePage(group)
posters = re.compile('<a href="(http://www.movieposterdb.com/poster/.*?)">', re.DOTALL).findall(html)
for poster in posters:
html = cache.getUrlUnicode(poster)
posterUrls.append(findRe(html, '"(http://www.movieposterdb.com/posters/.*?\.jpg)"'))
return posterUrls
def getData(id):
data = {
"url": getUrl(id)
}
data["posters"] = getPostersByUrl(data["url"])
return data
def getId(url):
return url.split("/")[-2]
def getPostersByUrl(url):
posters = []
html = getUrlUnicode(url)
results = re.compile('<a href="(http://www.movieposterdb.com/group/.*?)">', re.DOTALL).findall(html)
for result in results:
posters += getPostersByUrl(result)
results = re.compile('<a href="(http://www.movieposterdb.com/poster/.*?)">', re.DOTALL).findall(html)
for result in results:
html = getUrlUnicode(result)
posters.append(findRe(html, '"(http://www.movieposterdb.com/posters/.*?\.jpg)"'))
return posters
def getUrl(id):
return "http://www.movieposterdb.com/movie/%s/" % id
if __name__ == '__main__':
print getPosterUrls('0133093')
print getPosterUrls('0060304')
print getData('0060304')
print getData('0133093')