import os,sys,re,urllib,string
reg = re.compile(r"[0-9]{1,3};")
def fix(s):
codes = reg.findall(s)
for i in codes:
s = s.replace(i,'%c'%(int(i.replace('','').replace(';','')))).replace('','').replace('','').replace('
','')
return(s)
def IMDbFunc(url):
sock = urllib.urlopen(url)
fromInfo = sock.read()
sock.close()
fromInfo = fromInfo.replace(' / ','').replace(' ',' ').replace('','').replace('\n\n
\n','')
sock = urllib.urlopen(url + 'plotsummary')
fromDetails = sock.read()
sock.close()
return fromInfo, fromDetails
fromInfo, fromDetails = IMDbFunc('http://www.imdb.com/title/tt0315824/')
def Title(fromInfo):
# Movie's Title fromInfo saved into a list
in_title = re.compile('
(.*)<.*?')
Title = in_title.findall(fromInfo)
return Title
print Title(fromInfo)
def Year(fromInfo):
# Movie's Year fromInfo saved into a list
in_year = re.compile('/Sections/Years/([0-9]*)')
Year = in_year.findall(fromInfo)
return Year
print Year(fromInfo)
def Directors(fromInfo):
# Movie's Directors fromInfo saved into a list
in_directors = re.compile('.*?Directed by.*\n(.*)')
get_directors = str(in_directors.findall(fromInfo))
from_directors = re.compile(']*>([^<]*)')
Directors = from_directors.findall(get_directors)
return Directors
print Directors(fromInfo)
def MPAA(fromInfo):
#Movie's MPAA Rating fromInfo saved into a list
in_mpaa = re.compile('MPAA:([^<]*)<')
MPAA = in_mpaa.findall(fromInfo)
return MPAA
print MPAA(fromInfo)
def Tagline(fromInfo):
# Movie's Tagline fromInfo saved into a list
in_tagline = re.compile('Tagline:([^<]*)<')
tagline = in_tagline.findall(fromInfo)
Tagline = []
for a in tagline:
Tagline.append(a.strip())
return Tagline
print Tagline(fromInfo)
def Runtime(fromInfo):
# Movie's Runtime fromInfo saved into a list
in_runtime = re.compile('Runtime:([^<]*)<')
runtime = in_runtime.findall(fromInfo)
Runtime = []
for a in runtime:
Runtime.append(runtime[0].replace('\n','').strip())
return Runtime
print Runtime(fromInfo)
def CoverURL(fromInfo):
# Movie's Cover Image URL fromInfo saved into a list
in_cover = re.compile('.*?(http://.*?m.jpg)".*')
CoverURL = in_cover.findall(fromInfo)
return CoverURL
print CoverURL(fromInfo)
def Writers(fromInfo):
# Movie's Writers saved into a list
in_writers = re.compile('ts\n.*\n.*\n(.*)\n')
get_writers = str(in_writers.findall(fromInfo))
from_writers = re.compile(']*>([^<]*)<')
Writers = from_writers.findall(get_writers)
return Writers
print Writers(fromInfo)
def Rating(fromInfo):
# Movie's IMDb Rating fromInfo saved into a list
in_rating = re.compile('(.*?) (.*)')
rating = in_rating.findall(fromInfo)
Rating = []
for a in rating:
Rating.append('%s %s' % (a[0],a[1]))
return Rating
print Rating(fromInfo)
def Genres(fromInfo):
in_genres = re.compile('Genres/(.*?)/')
Genres = in_genres.findall(fromInfo)
return Genres
print Genres(fromInfo)
def Details(fromDetails):
in_details = re.compile('(.*?)
')
Details = in_details.findall(fromDetails)
return Details
print Details(fromDetails)
def Plot(fromInfo):
in_plot = re.compile('Plot Outline:([^<]*)<')
Plot = in_plot.findall(fromInfo)
return Plot
print Plot(fromInfo)
def Cast(fromInfo):
# Movie's Actor & Alias names saved in separate lists
in_cast = re.compile(']*>([^<]*) | [. ]* | ([^<]*) | ')
Cast = in_cast.findall(fromInfo)
CastActor = []
CastAlias = []
for a in Cast:
CastActor.append(a[0])
CastAlias.append(a[1])
return CastActor, CastAlias
print Cast(fromInfo)
def Countries(fromInfo):
in_countries = re.compile('ries/(.*?)/')
Countries = in_countries.findall(fromInfo)
return Countries
print Countries(fromInfo)
def Languages(fromInfo):
in_languages = re.compile('uages/(.*?)/')
Languages = in_languages.findall(fromInfo)
return Languages
print Languages(fromInfo)
def Color(fromInfo):
in_color = re.compile('o=.*?">(.*?)<')
Color = in_color.findall(fromInfo)
return Color
print Color(fromInfo)
def SoundMix(fromInfo):
in_sound = re.compile('x=.*?">(.*?)')
Sound = in_sound.findall(fromInfo)
return Sound
print SoundMix(fromInfo)
def Certificates(fromInfo):
in_cert = re.compile('tes=.*?">(.*?)<')
Cert = in_cert.findall(fromInfo)
return Cert
print Certificates(fromInfo)