-
Notifications
You must be signed in to change notification settings - Fork 0
/
fetch.py
executable file
·48 lines (34 loc) · 1.28 KB
/
fetch.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
#!/usr/bin/env python3
import argparse
import json
import os
import sys
from urllib import request
SERVER = 'https://results.webkit.org/api/results/layout-tests'
def parse_args():
parser = argparse.ArgumentParser()
parser.add_argument('-d', '--dest-dir', metavar='DEST', help='Destination directory',
default=None)
return parser.parse_args()
def main():
args = parse_args()
mydir = os.path.dirname(os.path.abspath(__file__))
if args.dest_dir and not os.path.isdir(args.dest_dir):
print("Destination must be a valid directory")
sys.exit(1)
elif not args.dest_dir:
args.dest_dir = mydir
with open(os.path.join(mydir, 'bots.json')) as handle:
data = json.load(handle)
for platform, query in data.items():
print(platform, query)
outfilename = os.path.join(args.dest_dir, 'layout-tests-{}.json'.format(platform))
print('Saving to {}'.format(outfilename))
with request.urlopen('{}?{}'.format(SERVER, query)) as response:
print('Fetching {}...'.format(platform))
data = response.read()
with open(outfilename, 'wb') as handle:
print('Saving to {}'.format(outfilename))
handle.write(data)
if __name__ == "__main__":
main()