-
Notifications
You must be signed in to change notification settings - Fork 0
/
jonnyguru_crawler.py
48 lines (33 loc) · 944 Bytes
/
jonnyguru_crawler.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
"""JonnyGuru PSU Crawler
Usage:
jonnyguru_crawler.py crawl
jonnyguru_crawler.py sort <file_path>
jonnyguru_crawler.py (-h | --help)
jonnyguru_crawler.py --version
Options:
-h --help Show this screen.
--version Show version.
"""
import json
from docopt import docopt
def crawl():
pass
def sort(file_path):
all_results = []
with open(file_path, 'r') as results:
for line in results.readlines():
all_results.append(json.loads(line))
all_results.sort(key=sort_how, reverse=True)
print(all_results[:10])
def sort_how(elem):
try:
return float(elem['scores']['total_score'] or '0.0')
except ValueError:
return 0.0
if __name__ == '__main__':
arguments = docopt(__doc__, version='JonnyGuru PSU Crawler v0.0.1')
if arguments['crawl']:
crawl()
if arguments['sort']:
file_path = arguments['<file_path>']
sort(file_path)