-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathimdbCLI.py
More file actions
58 lines (47 loc) · 1.45 KB
/
Copy pathimdbCLI.py
File metadata and controls
58 lines (47 loc) · 1.45 KB
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
#!C:\Python27
import argparse
import urllib
import sys
from xml.etree import ElementTree
def retrieve_movie(title):
title = urllib.quote(title.encode("utf8"))
URL="http://www.omdbapi.com/?r=xml&plot=full&t=%s" % title
xml = ElementTree.parse(urllib.urlopen(URL))
for A in xml.iter('root'):
if(A.get('respone')==False):
print "movie not found"
sys.exit()
xml=xml.getroot()
printInfo(xml)
return xml
def search_movie(title):
title = urllib.quote(title.encode("utf8"))
URL="http://www.omdbapi.com/?r=xml&s=%s" % title
xml = ElementTree.parse(urllib.urlopen(URL))
xml = xml.getroot()
for B in xml.findall('Movie'):
apicall=retrieve_movie(B.get('Title'))
printInfo(apicall)
return xml
def printInfo(xml):
for B in xml.findall('movie'):
print "\n%s %s || %s || %s\n" % (B.get('title'), B.get('year'), B.get('runtime'), B.get('imdbRating'))
print "Genre : %s" %(B.get('genre'))
print "Director: %s\n Actors: %s\n" %(B.get('director'), B.get('actors'))
print "%s\n" % (B.get('plot'))
if __name__ == '__main__':
parser = argparse.ArgumentParser(description='Command-Line interface for IMDB')
parser.add_argument('-t', help='Search by title, returns first result')
parser.add_argument('-s', help='Search and return result')
args = parser.parse_args()
choices=['None']
try:
choices[0]=sys.argv[1]
value=sys.argv[2]
except:
parser.print_usage()
sys.exit()
if choices[0]=='-t':
retrieve_movie(value)
else:
search_movie(value)