-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathimdb_score.py
73 lines (50 loc) · 2.33 KB
/
imdb_score.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#!/usr/bin/python
# -*- coding: utf8 -*-
#Author Παναγιώτης Πράττης/Panagiotis Prattis
'''
Write a program which takes for input a title of a movie that the user choses and by using the link
http://www.omdbapi.com/ it returns the IMDB score and the awards that it may has.
'''
'''
These are all the fields that you can search for any movie, we search for title, imdbrating and awards
Example:
{"Title":"Inception","Year":"2010","Rated":"PG-13","Released":"16 Jul 2010","Runtime":"148 min","Genre":"Action, Adventure, Sci-Fi",
"Director":"Christopher Nolan","Writer":"Christopher Nolan","Actors":"Leonardo DiCaprio, Joseph Gordon-Levitt, Ellen Page, Tom Hardy",
"Plot":"A thief, who steals corporate secrets through use of dream-sharing technology, is given the inverse task of planting an idea into the mind of a CEO.",
"Language":"English, Japanese, French","Country":"USA, UK","Awards":"Won 4 Oscars. Another 143 wins & 198 nominations.",
"Poster":"http://ia.media-imdb.com/images/M/MV5BMjAxMzY3NjcxNF5BMl5BanBnXkFtZTcwNTI5OTM0Mw@@._V1_SX300.jpg","Metascore":"74",
"imdbRating":"8.8","imdbVotes":"1,477,526","imdbID":"tt1375666","Type":"movie","Response":"True"}
'''
import json, requests
from imdb import IMDb
import omdb
import imdb
import urllib
from jabbapylib.web.web import get_page
BASE = 'http://www.omdbapi.com/?i=&'
class Movie(object):
def __init__(self, keyword):
self.keyword = keyword
self.url = BASE + urllib.urlencode({'t' : keyword})
self.d = self.get_info()
def get_info(self):
text = get_page(self.url)
return json.loads(text)
def __getitem__(self, key):
return self.d[key]
def __str__(self):
li = []
for key in self.d:
li.append("{key}: {value}".format(key=key, value=self.d[key]))
return '\n'.join(li)
def get_rating(title):
m = Movie(title)
return float(m['imdbRating'])
if __name__ == "__main__":
m = Movie(raw_input('Enter movie title: '))
while m['Response']=='False':
m = Movie(raw_input('Please, re-enter movie title:'))
print 'Title: {title}'.format(title=m['Title'])
print 'Year: {year}'.format(year=m['Year'])
print 'Rating: {rating}'.format(rating=m['imdbRating'])
print 'Awards: {awards}'.format(awards=m['Awards'])