All pastes #173034 Raw Edit

Unnamed

public python v1 · immutable
·published 2006-09-16 14:15 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)def replaceOne(args):    return (args * 1) + (args == 0)class IMDb:    def __init__(self, url, Info=False, Details=False, Gallery=False):        if Info == True:            fromInfo         = urllib.urlopen(url).read()            self.fromInfo    = fix(fromInfo).replace(' / ','').replace('</a> <i>',' ').replace('</i>','</a>')        if Details == True:                self.fromDetails = urllib.urlopen(url + 'plotsummary').read()        if Gallery == True:            self.fromGallery = urllib.urlopen(url + 'photogallery').read()def Galleries(fromGallery, page='0'):    in_gallery = re.compile('"(photogallery.*?|/gallery/.*?)"><img src="(.*?jpg)"')    in_next    = re.compile('="(.*?)">.*more')        Gallery   = []    GalInfo   = []    Galhtml   = []    Next      = []    GalImage  = []    Images    = []    for a in in_gallery.findall(fromGallery):        Gallery.append([a[0]])        Galhtml.append(urllib.urlopen(url + a[0]).read())    for a in Galhtml:        Next   = in_next.findall(a)        Images = in_gallery.findall(a)        for a in Next:            GalImage.append(urllib.urlopen(url + a).read())            Next = in_next.findall(a)        print Next        if Next > 0:            for a in Next:                Images.append(in_gallery.findall(a))        else:            switch = False        print Images                             #for a in imgLeft:    #    pgLeft.append(in_pgLeft.findall(a))    #for a in pgLeft:    #    GalInfo.append(int(str(a)[2:-2]) / 12)    #for cnt, item in enumerate(GalInfo): GalInfo[cnt] = (item * 1) + (item == 0)    ##for cnt in range(0,25,12):    #    #Links = Gallery[0][:Gallery[0].rfind('-')] + str(int(Gallery[0][Gallery[0].rfind('-') + 1:]) + 12)    #    #Links = []    #print GalInfo    #for b in GalInfo:    #    print b    #    for cnt in range(b):    #        print cnt    #        Links.append(url + Gallery[cnt][:-1] + str(cnt * 12))    #print Links    num = '0'url = 'http://www.imdb.com/title/tt0315824/'imdb = IMDb(url, Gallery=True)gal = Galleries(imdb.fromGallery, page=num)#print gal#print thumb