-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhistogram-year
executable file
·70 lines (60 loc) · 2.04 KB
/
histogram-year
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
#!/usr/bin/env python
"""
Output year histogram for movies in IMDB, for use when creating a graph.
"""
import argparse
import json
def load(h, l, stats, path, verbose=False, cutyear=None):
#print("Loading %s" % path)
with open(path, 'rt') as input:
j = json.load(input)
for imdburl in j.keys():
if imdburl in l:
continue
if 0 > imdburl.find("imdb.com"):
continue
if 'status' not in j[imdburl] or 'free' != j[imdburl]['status']:
continue
if 'year' not in j[imdburl]:
year = 'n/a'
else:
#print j[imdburl]
year = int(j[imdburl]['year'])
if cutyear:
if year < cutyear:
stats['before'] = stats['before'] + 1
else:
stats['after'] = stats['after'] + 1
if not year in h:
h[year] = 0
if verbose:
print imdburl, j[imdburl]['title']
h[year] = h[year] + 1
l[imdburl] = j[imdburl]
def main():
parser = argparse.ArgumentParser()
parser.add_argument('files', metavar='N', type=str, nargs='*',
default=['free-movies-manual.json'],
help='input file(s)')
parser.add_argument('--cutyear', type=int, default=None,
help='Report movie count before and after this year')
parser.add_argument('--total', action='store_true', default=False)
args = parser.parse_args()
h = {}
l = {}
stats = {
'before' : 0,
'after' : 0
}
for file in args.files:
load(h, l, stats, file, cutyear=args.cutyear)
for y in sorted(h.keys()):
#print y
print("%s %s" % (y, h[y]))
if args.total:
print "Total:", len(l.keys())
if args.cutyear:
print("Cutyear %d. %d before, %d after" %
(args.cutyear, stats['before'], stats['after']))
if __name__ == '__main__':
main()