-
Notifications
You must be signed in to change notification settings - Fork 3
/
folo-to-csv.py
executable file
·48 lines (34 loc) · 1.09 KB
/
folo-to-csv.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
#!/usr/bin/env python
import json
import os
import sys
if len(sys.argv) < 3:
print "Usage: %s <json-dir> <csv-dir>" % sys.argv[0]
exit(1)
JSON_DIR=sys.argv[1]
CSV_DIR=sys.argv[2]
if not os.path.isdir(CSV_DIR):
os.makedirs(CSV_DIR)
count=0
for filename in os.listdir(JSON_DIR):
paths=[]
print "Processing %s" % filename
with open(os.path.join(JSON_DIR, filename)) as f:
data=json.load(f)
if data.get('affectedStores') is None:
continue
central = data['affectedStores'].get('remote:central')
if central is not None and central.get('downloadedPaths') is not None:
for path in central['downloadedPaths']:
paths.append(path)
sharedImports = data['affectedStores'].get('hosted:shared-imports')
if sharedImports is not None and sharedImports.get('downloadedPaths') is not None:
for path in sharedImports['downloadedPaths']:
paths.append(path)
csvname="downloads-%s.csv" % count
print "Writing %s" % csvname
with open(os.path.join(CSV_DIR, csvname), 'w') as f:
f.write("\n".join(paths))
f.write('\n')
count+=1
print "Wrote %s CSV files to: %s" % (count, CSV_DIR)