-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmovie_info.py
executable file
·36 lines (32 loc) · 1.07 KB
/
movie_info.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import re
import requests
import urllib
import json
BASE_URL = 'http://www.imdbapi.com/?'
#NAME_LIST = file('movies.txt','r')
def get_movie_info(movi_name):
query = {'i': '', 't': movi_name ,'tomatoes':'true'}
part = urllib.urlencode(query)
url = BASE_URL+part
response = requests.get(url)
output = json.dumps(response.content, separators=(',',':'))
movie_info = {}
info_list = ['Plot','Title','Director','tomatoRating', 'imdbRating', 'Runtime']
for info in info_list:
if info == 'imdbRating':
movie_info['IMDB Rating'] = get_and_clean_data(info, output)
movie_info[info] = get_and_clean_data(info, output)
return movie_info
def get_and_clean_data(tag, data):
try:
temp_data = data.split(tag)[1].split(",")[0]
data = re.sub(r':\\"+','',temp_data).replace('\\"','')
except IndexError,e:
print "Error Occured! %s" %e
return ""
return data
#def get_movi_name(name_list):
# for name in name_list:
# print "Getting Movi %s " % name
# print get_movie_info(name)
# return