# -*- coding: utf-8 -*-
# vi:si:et:sw=4:sts=4:ts=4
import re
import time
from ox import stripTags, findRe
from ox.cache import readUrlUnicode
def getId(url):
return url.split("/")[-1]
def getData(id):
'''
>>> getData('129689')['cast'][1][1]
u'Marianne'
>>> getData('129689')['credits'][0][0]
u'Jean-Luc Godard'
>>> getData('129689')['posters'][0]
u'http://image.allmusic.com/00/adg/cov200/dru800/u812/u81260bbffr.jpg'
>>> getData('129689')['rating']
u'4.5'
'''
if id.startswith('http'):
id = getId(id)
data = {
"url": getUrl(id)
}
html = readUrlUnicode(data["url"])
data['aka'] = parseList(html, 'AKA')
data['category'] = findRe(html, '
category.*?(.*?)')
data['countries'] = parseList(html, 'countries')
data['director'] = parseEntry(html, 'directed by')
data['genres'] = parseList(html, 'genres')
data['keywords'] = parseList(html, 'keywords')
data['posters'] = [findRe(html, '(.*?)')).strip()
data['themes'] = parseList(html, 'themes')
data['types'] = parseList(html, 'types')
data['year'] = findRe(html, '.*?(\d+)')
#data['stills'] = [re.sub('_derived.*?/', '', i) for i in re.compile('(.*?)')).strip()
return data
def getUrl(id):
return "http://allmovie.com/work/%s" % id
def parseEntry(html, title):
html = findRe(html, '%s.*?(.*?)' % title)
return stripTags(html).strip()
def parseList(html, title):
html = findRe(html, '%s.*?(.*?)' % title.lower())
r = map(lambda x: stripTags(x), re.compile('(.*?)', re.DOTALL).findall(html))
if not r and html:
r = [stripTags(html)]
return r
def parseTable(html):
return map(
lambda x: map(
lambda x: stripTags(x).strip().replace(' ', ''),
x.split('-')
),
findRe(html, ' (.*?)').split('')[:-1]
)
def parseText(html, title):
return stripTags(findRe(html, '%s | .*?(.*?) | ' % title)).strip()
if __name__ == '__main__':
print getData('129689')
# print getData('177524')