-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfetch_files.py
46 lines (36 loc) · 934 Bytes
/
fetch_files.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
import sys, getopt
import json
import requests
argv = sys.argv[1:]
print "Fetching remote files..."
outputdir = 'resources'
try:
opts, args = getopt.getopt(argv, ":o:", ["odir="])
except getopt.GetoptError:
print 'fetch_files.py -o <outputdir>'
sys.exit(2)
for opt, arg in opts:
if opt in ("-o", "--odir"):
outputdir = arg
# Script
objects_file = "resources/objects.json"
json_ = open(objects_file, mode='r').read()
objects_ = json.loads(json_)["objects"]
baseurl = json.loads(json_)['baseurl']
for o in objects_:
url = o['url']
if url[0] == '/':
url = baseurl + url
response = requests.get(url)
if response.status_code != 200:
continue
response = json.loads(response.text)
filename = o['filename']
o_dump = json.dumps(
response,
indent=4,
sort_keys=True
)
file = open(filename, 'w')
file.write(o_dump)
file.close()