forked from bgr/omdb-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathimdbtool
More file actions
executable file
·44 lines (34 loc) · 1.2 KB
/
imdbtool
File metadata and controls
executable file
·44 lines (34 loc) · 1.2 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
#!/usr/bin/python3
import argparse
import urllib.request, urllib.parse, urllib.error
import sys
import json
parser = argparse.ArgumentParser(description='Get IMDb data for a movie')
parser.add_argument("-t", help="Movie title")
parser.add_argument("-y", help="Year of release", type=int)
parser.add_argument("-i", help="IMDb movie id")
parser.add_argument("-r", help="Return raw XML/JSON response", choices=['JSON','XML'])
parser.add_argument("--plot", help="Length of plot summary", choices=['short','full'])
parser.add_argument("--tomatoes", help="Include Rotten Tomatoes data too", action="store_true")
args = parser.parse_args()
params = {}
keys = ['t', 'y', 'i', 'plot', 'r', 'tomatoes']
for k in keys:
if args.__getattribute__(k): params[k] = args.__getattribute__(k)
if len(params) == 0:
parser.print_usage()
sys.exit()
### call IMDb API
apicall = urllib.request.urlopen('http://www.omdbapi.com/?%s' % urllib.parse.urlencode(params))
result = apicall.read().decode('utf-8')
apicall.close()
# print raw output and exit, if raw output was requested
if args.r:
print(result)
sys.exit()
# print requested info
data = json.loads(result)
for k in data:
print(k.lower() + ":")
print(data[k])
print("\n")