All pastes #73764 Raw Edit

Miscellany

public python v1 · immutable
#73764 ·published 2006-06-28 07:36 UTC
rendered paste body
import os,sys,re,urllib#NZB_ = {'Details':[], 'Genre':[], 'Year':[], 'Tagline':[], 'Plot':[], 'Rating':[], 'Runtime':[], 'Actor':[], 'Alias':[]}def Title(url):    IMDb_ = {'Title':[]}    title = re.compile(r'<title>.*')    in_title = re.compile(r'<title>(.*?)</title>')    sock = urllib.urlopen(url)    page = sock.readlines()    sock.close()    for i in page:        if title.match(i) != None:            try:                IMDb_['Title'].append(in_title.search(i).group(1).strip())            except:                IMDb_['Title'].append('None')    return str(IMDb_['Title'])[2:-2]def Details(url):    IMDb_ = {'Details':[]}    details = re.compile(r'<p class="plotpar">.*')    in_details = re.compile(r'">(.*?)</p>')    sock = urllib.urlopen(url)    page = sock.readlines()    sock.close()    for i in page:        if details.match(i) != None:            try:                IMDb_['Details'].append(in_details.search(i).group(1).strip())            except:                IMDb_['Details'].append('None')    return str(IMDb_['Details'])[2:-2]def Genre(url):    IMDb_ = {'Genre':[]}    genres = re.compile(r'<a href="/Sections/Genres/.*')    in_genres = re.compile(r'<a href="/Sections/Genres/(.*?)/')    sock = urllib.urlopen(url)    page = sock.readlines()    sock.close()    for i in page:        if genres.match(i) != None:            try:                IMDb_['Genre'].append(in_genres.search(i).group(1).strip())            except:                IMDb_['Genre'].append('None')    return str(IMDb_['Genre'])[2:-2]def Year(url):    IMDb_ = {'Year':[]}    year = re.compile(r'.*<a href="/Sections/Years/.*')    in_year = re.compile(r'<a href="/Sections/Years/.*">(.*?)</a>')    sock = urllib.urlopen(url)    page = sock.readlines()    sock.close()    for i in page:        if year.match(i) != None:            try:                IMDb_['Year'].append(in_year.search(i).group(1).strip())            except:                IMDb_['Year'].append('None')    return str(IMDb_['Year'])[2:-2]def Tagline(url):    IMDb_ = {'Tagline':[]}    tagline = re.compile(r'<b class="ch">Tagline:</b>.*')    in_tagline = re.compile(r"</b>(.*)")    sock = urllib.urlopen(url)    page = sock.readlines()    sock.close()    for i in page:        if tagline.match(i) != None:            try:                IMDb_['Tagline'].append(in_tagline.search(i).group(1).strip())            except:                IMDb_['Tagline'].append('None')    return str(IMDb_['Tagline'])[2:-72]def Plot(url):    IMDb_ = {'Plot':[]}    plot = re.compile(r'<b class="ch">Plot Outline:</b>.*')    in_plot = re.compile(r"</b>(.*?)<a href")    sock = urllib.urlopen(url)    page = sock.readlines()    sock.close()    for i in page:        if plot.match(i) != None:            try:                IMDb_['Plot'].append(in_plot.search(i).group(1).strip())            except:                IMDb_['Plot'].append('None')    return str(IMDb_['Plot'])[2:-2]def Rating(url):    IMDb_ = {'Rating':[]}    rating = re.compile(r'<b>.*/.*</b>.*')    in_rating = re.compile(r"<b>(.*?)/.*</b> .*")    sock = urllib.urlopen(url)    page = sock.readlines()    sock.close()    for i in page:        if rating.match(i) != None:            try:                IMDb_['Rating'].append(in_rating.search(i).group(1).strip())            except:                IMDb_['Rating'].append('None')    return str(IMDb_['Rating'][0])def Runtime(url):    IMDb_ = {'Runtime':[]}    runtime = re.compile(r'(.*?) min')    in_runtime = re.compile(r"(.*?) min")    sock = urllib.urlopen(url)    page = sock.readlines()    sock.close()    for i in page:        if runtime.match(i) != None:            try:                IMDb_['Runtime'].append(in_runtime.search(i).group(1).strip())            except:                IMDb_['Runtime'].append('None')    return str(IMDb_['Runtime'][0]) + " min"def Director(url):    IMDb_ = {'Director':[]}    director = re.compile(r'<b class="blackcatheader">Directed by</b><br>')    in_director = re.compile(r'.*?">(.*?)</.*?')    sock = urllib.urlopen(url)    page = sock.readlines()    sock.close()            for i in range(len(page)):        if director.search(page[i]) != None:            i+=1            while in_director.search(page[i]) != None:                IMDb_['Director'].append(in_director.findall(page[i])) #.group(1))                i+=1        else:            i+=1            #IMDb_['Director'].append('None')    return str(IMDb_['Director'])[2:-2]def Writer(url):    IMDb_Writer = []    IMDb_Writer1 = []    writer = re.compile(r'<b class="blackcatheader">Writing credits</b>')    in_writer = re.compile(r'.*?">(.*?)</.*?')    sock = urllib.urlopen(url)    page = sock.readlines()    sock.close()            for i in range(len(page)):        if writer.search(page[i]) != None:            i+=3            while in_writer.search(page[i]) != None:                IMDb_Writer.append(in_writer.findall(page[i]))                i+=3        else:            i+=3    return str(IMDb_Writer)[2:-2]detail = Details("http://www.imdb.com/title/tt0317219/plotsummary")print detailgenre = Genre("http://www.imdb.com/title/tt0317219/")print genredirector = Director("http://www.imdb.com/title/tt0317219/")print director#writer = Writer("http://www.imdb.com/title/tt0441694/")writer = Writer("http://www.imdb.com/title/tt0317219/")print writeryear = Year("http://www.imdb.com/title/tt0317219/")print yeartagline = Tagline("http://www.imdb.com/title/tt0317219/")print taglineplot = Plot("http://www.imdb.com/title/tt0317219/")print plotrating = Rating("http://www.imdb.com/title/tt0317219/")print ratingruntime = Runtime("http://www.imdb.com/title/tt0317219/")print runtime