-
Notifications
You must be signed in to change notification settings - Fork 5
/
build.py
executable file
·39 lines (28 loc) · 1.04 KB
/
build.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
#!/usr/bin/env python3
from parliament_parser import ParliamentarySession
import os
import sys
import json
from os import path, makedirs
from distutils.dir_util import copy_tree
OUTPUT_PATH = "build"
STATIC_SITE_PATH = "static"
def session_to_URL(session):
session = int(session)
parliamentary_session = ParliamentarySession(session)
return parliamentary_session.dump_json(OUTPUT_PATH, sys.argv[1])
def print_usage():
print(f'{sys.argv[0]} <base_url> <session> <session> ...')
def main():
if len(sys.argv) > 1 and sys.argv[1] == "--help":
print_usage()
os.makedirs(OUTPUT_PATH, exist_ok=True)
# Use a single thread to prevent us being blocked during long runs
urls = list(map(session_to_URL, sys.argv[2:]))
sessions = {value: urls[idx] for idx, value in enumerate(sys.argv[2:])}
makedirs(OUTPUT_PATH, exist_ok=True)
copy_tree("static", "build")
with open(path.join(OUTPUT_PATH, 'index.json'), 'w+') as fp:
json.dump(sessions, fp, ensure_ascii='false')
if __name__ == "__main__":
main()