All pastes #166098 Raw Edit

Unnamed

public python v1 · immutable
·published 2006-09-10 15:30 UTC
rendered paste body
import os, sys, re, urllib, stringreg = 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('<em>','').replace('</em>','') #.replace('<br>','')    return(s)class IMDb:    def __init__(self, url):        fromInfo         = urllib.urlopen(url).read()        self.fromInfo    = fix(fromInfo).replace(' / ','').replace('</a> <i>',' ').replace('</i>','</a>')        self.fromDetails = urllib.urlopen(url + 'plotsummary').read()        self.fromGallery = urllib.urlopen(url + 'photogallery').read()    def Title(fromInfo):    # Movie's Title fromInfo saved into a list    in_title = re.compile('<title>(.*)<.*?')    return in_title.findall(fromInfo)def Year(fromInfo):    # Movie's Year fromInfo saved into a list    in_year = re.compile('/Sections/Years/([0-9]*)')    return in_year.findall(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('<a [^>]*>([^<]*)</a>')    return from_directors.findall(get_directors)def MPAA(fromInfo):    #Movie's MPAA Rating fromInfo saved into a list    in_mpaa = re.compile('MPAA</a>:</b>([^<]*)<')    return in_mpaa.findall(fromInfo)def Tagline(fromInfo):    # Movie's Tagline fromInfo saved into a list    in_tagline = re.compile('Tagline:</b>([^<]*)<')    Tagline    = []    for a in in_tagline.findall(fromInfo):        Tagline.append(a.strip())    return Taglinedef Runtime(fromInfo):    # Movie's Runtime fromInfo saved into a list    in_runtime = re.compile('me:</b>\n(.*)')    Runtime    = []    for a in in_runtime.findall(fromInfo):        Runtime.append(a.strip())    return Runtime    def CoverURL(fromInfo):    # Movie's Cover Image URL fromInfo saved into a list    in_cover = re.compile('(http://.*?m.jpg)')    return in_cover.findall(fromInfo)def Writers(fromInfo):    # Movie's Writers saved into a list    in_writers   = re.compile('ts</b>\n.*\n.*\n(.*)') #\n')    get_writers  = str(in_writers.findall(fromInfo))    from_writers = re.compile('/">(.*?)<')    return from_writers.findall(get_writers)    def Rating(fromInfo):    # Movie's IMDb Rating fromInfo saved into a list    in_rating = re.compile('<b>(.*?)</b> (.*)')    Rating    = []    for a in in_rating.findall(fromInfo):        Rating.append('%s %s' % (a[0],a[1]))    return Ratingdef Genres(fromInfo):    in_genres = re.compile('res/(.*?)/')    return in_genres.findall(fromInfo)def Details(fromDetails):    in_details = re.compile('ar">(.*?)<')    return in_details.findall(fromDetails)def Plot(fromInfo):    in_plot = re.compile('tline:</b>([^<]*)<')    return in_plot.findall(fromInfo)def Cast(fromInfo):    # Movie's Actor & Alias names saved in separate lists    in_cast   = re.compile('d valign=.*?/">(.*?)<.*?e">(.*?)<')    Cast      = in_cast.findall(fromInfo)    CastActor = []    CastAlias = []    for a in Cast:        CastActor.append(a[0])        CastAlias.append(a[1])    return CastActor, CastAliasdef Countries(fromInfo):    in_countries = re.compile('ries/(.*?)/')    return in_countries.findall(fromInfo)def Languages(fromInfo):    in_languages = re.compile('uages/(.*?)/')    return in_languages.findall(fromInfo)    def Color(fromInfo):    in_color = re.compile('o=.*?">(.*?)<')    return in_color.findall(fromInfo)def SoundMix(fromInfo):    in_sound = re.compile('x=.*?">(.*?)</a>')    return in_sound.findall(fromInfo)def Certificates(fromInfo):    in_cert = re.compile('tes=.*?">(.*?)<')    return in_cert.findall(fromInfo)def Trivia(fromInfo):    in_trivia = re.compile('ia:</b>\n(.*)')    return in_trivia.findall(fromInfo)def Goofs(fromInfo):    in_goofs = re.compile('fs:</b>\n(.*)')    return in_goofs.findall(fromInfo)def Quotes(fromInfo):    in_qoutes  = re.compile('">(.*?)</a></b>:\n(.*?)<')    Quotes = []    for a in in_qoutes.findall(fromInfo):        Quotes.append('%s: %s' % (a[0], a[1]))    return Quotesdef Galleries(fromGallery, page='0'):    in_gallery = re.compile('"(photogallery.*?|/gallery/.*?)"><img src="(.*?jpg)"')    Gallery = []    Thumbs  = []    for a in in_gallery.findall(fromGallery):        Gallery.append(a[0])        thumbs = urllib.urlopen(url + a[0][:-1] + page).read()        test   = in_gallery.findall(thumbs)        for a in test:            Thumbs.append(a[1].replace('th-',''))    return Gallery, Thumbsnum = '0'Next = int(num) + 12url = 'http://www.imdb.com/title/tt0315824/'Gallery = IMDb(url).fromGallerygal, thumb = Galleries(Gallery, page=num)print galprint thumb#print Title(fromInfo)#print Year(fromInfo)#print Directors(fromInfo)#print MPAA(fromInfo)#print Tagline(fromInfo)#print Runtime(fromInfo)#print CoverURL(fromInfo)#print Writers(fromInfo)#print Rating(fromInfo)#print Genres(fromInfo)#print Details(fromDetails)#print Plot(fromInfo)#print Cast(fromInfo)#print Countries(fromInfo)#print Languages(fromInfo)#print Color(fromInfo)#print SoundMix(fromInfo)#print Certificates(fromInfo)#print Trivia(fromInfo)#print Goofs(fromInfo)#print Quotes(fromInfo)