Skip to content

Commit 79fb961

Browse files
committed
Merge pull request #3 from kenorb/master
Added option to execute the script directly
2 parents 04a3cb8 + 1aaf67f commit 79fb961

1 file changed

Lines changed: 47 additions & 46 deletions

File tree

imdbtool.py

100644100755
Lines changed: 47 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,47 @@
1-
import argparse
2-
import urllib
3-
import sys
4-
import json
5-
6-
parser = argparse.ArgumentParser(description='Get IMDb data for a movie')
7-
8-
parser.add_argument("-t", help="Movie title")
9-
parser.add_argument("-y", help="Year of release", type=int)
10-
parser.add_argument("-i", help="IMDb movie id")
11-
parser.add_argument("-r", help="Return raw XML/JSON response", choices=['JSON','XML'])
12-
parser.add_argument("--plot", help="Length of plot summary", choices=['short','full'])
13-
parser.add_argument("--tomatoes", help="Include Rotten Tomatoes data too", action="store_true")
14-
15-
args = parser.parse_args()
16-
17-
params = {}
18-
keys = ['t', 'y', 'i', 'plot', 'r', 'tomatoes']
19-
20-
for k in keys:
21-
if args.__getattribute__(k): params[k] = args.__getattribute__(k)
22-
23-
if len(params) == 0:
24-
parser.print_usage()
25-
sys.exit()
26-
27-
28-
### call IMDb API
29-
30-
apicall = urllib.urlopen('http://www.imdbapi.com/?%s' % urllib.urlencode(params))
31-
result = apicall.read()
32-
apicall.close()
33-
34-
# print raw output and exit, if raw output was requested
35-
if args.r:
36-
print result
37-
sys.exit()
38-
39-
40-
# print requested info
41-
42-
data = json.loads(result)
43-
for k in data:
44-
print k.lower() + ":"
45-
print data[k].encode('utf-8')
46-
print "\n"
1+
#!/usr/bin/env python
2+
3+
import argparse
4+
import urllib
5+
import sys
6+
import json
7+
8+
parser = argparse.ArgumentParser(description='Get IMDb data for a movie')
9+
10+
parser.add_argument("-t", help="Movie title")
11+
parser.add_argument("-y", help="Year of release", type=int)
12+
parser.add_argument("-i", help="IMDb movie id")
13+
parser.add_argument("-r", help="Return raw XML/JSON response", choices=['JSON','XML'])
14+
parser.add_argument("--plot", help="Length of plot summary", choices=['short','full'])
15+
parser.add_argument("--tomatoes", help="Include Rotten Tomatoes data too", action="store_true")
16+
17+
args = parser.parse_args()
18+
19+
params = {}
20+
keys = ['t', 'y', 'i', 'plot', 'r', 'tomatoes']
21+
22+
for k in keys:
23+
if args.__getattribute__(k): params[k] = args.__getattribute__(k)
24+
25+
if len(params) == 0:
26+
parser.print_usage()
27+
sys.exit()
28+
29+
30+
### call IMDb API
31+
32+
apicall = urllib.urlopen('http://www.imdbapi.com/?%s' % urllib.urlencode(params))
33+
result = apicall.read()
34+
apicall.close()
35+
36+
# print raw output and exit, if raw output was requested
37+
if args.r:
38+
print result
39+
sys.exit()
40+
41+
# print requested info
42+
43+
data = json.loads(result)
44+
for k in data:
45+
print k.lower() + ":"
46+
print data[k].encode('utf-8')
47+
print "\n"

0 commit comments

Comments
 (0)