2008-07-03 20:22:32 +00:00
|
|
|
# -*- coding: UTF-8 -*-
|
|
|
|
# vi:si:et:sw=4:sts=4:ts=4
|
|
|
|
import re
|
|
|
|
|
2009-10-12 15:18:59 +00:00
|
|
|
from oxlib.cache import getHeaders, readUrl, readUrlUnicode
|
|
|
|
from oxlib import findRe, stripTags
|
2008-07-03 20:22:32 +00:00
|
|
|
|
|
|
|
|
2009-10-12 11:47:43 +00:00
|
|
|
def readUrlByImdb(imdb):
|
2008-07-03 20:22:32 +00:00
|
|
|
#this would also wor but does not cache:
|
|
|
|
'''
|
|
|
|
from urllib2 import urlopen
|
|
|
|
u = urlopen(url)
|
|
|
|
return u.url
|
|
|
|
'''
|
|
|
|
url = "http://www.rottentomatoes.com/alias?type=imdbid&s=%s" % imdb
|
2009-10-12 11:47:43 +00:00
|
|
|
data = readUrl(url)
|
2008-07-03 20:22:32 +00:00
|
|
|
if "movie_title" in data:
|
|
|
|
movies = re.compile('(/m/.*?/)').findall(data)
|
|
|
|
if movies:
|
|
|
|
return "http://www.rottentomatoes.com" + movies[0]
|
|
|
|
return None
|
|
|
|
|
|
|
|
def getData(url):
|
2009-10-12 11:47:43 +00:00
|
|
|
data = readUrlUnicode(url)
|
2008-07-03 20:22:32 +00:00
|
|
|
r = {}
|
|
|
|
r['title'] = findRe(data, '<h1 class="movie_title">(.*?)</h1>')
|
|
|
|
if '(' in r['title']:
|
|
|
|
r['year'] = findRe(r['title'], '\((\d*?)\)')
|
|
|
|
r['title'] = re.sub('\((\d*?)\)', '', r['title']).strip()
|
|
|
|
r['synopsis'] = findRe(data, '<span id="movie_synopsis_all".*?>(.*?)</span>')
|
|
|
|
r['average rating'] = findRe(data, '<div id="bubble_allCritics".*?>(.*?)</div>').strip()
|
|
|
|
return r
|
|
|
|
|