From 9966d52a8ae95bf2eb510ce4a0056dbd545f2eff Mon Sep 17 00:00:00 2001 From: mark Date: Tue, 21 Jan 2025 22:48:32 -0800 Subject: [PATCH] Publish index --- tools/build/publish.py | 35 ++++++++++++++++++++++++++++++----- 1 file changed, 30 insertions(+), 5 deletions(-) diff --git a/tools/build/publish.py b/tools/build/publish.py index 89e0984..dcfb0c1 100644 --- a/tools/build/publish.py +++ b/tools/build/publish.py @@ -38,21 +38,46 @@ index = SRC_DIR / "index.json" with index.open("r") as f: index = json.load(f) +new_index = [] for handout in index: title = handout["title"] group = handout["group"] h_file = SRC_DIR/handout["handout_file"] s_file = SRC_DIR/handout["handout_file"] + h_url = None + s_url = None + target = f"{group} - {title}.pdf" requests.put( f"{URL}/api/packages/{USER}/generic/{PACKAGE}/{VERSION}/{target}", - auth=AUTH, data=h_file.open('rb').read()) - + auth=AUTH, + data=h_file.open('rb').read() + ) + h_url = f"{URL}/api/packages/{USER}/generic/ormc-handouts/{VERSION}/{target}" + + if s_file is not None: target = f"{group} - {title}.sols.pdf" requests.put( - f"{URL}/api/packages/{USER}/generic/{PACKAGE}/{VERSION}/{target}", - auth=AUTH, data=s_file.open('rb').read()) + f"{URL}/api/packages/{USER}/generic/{PACKAGE}/{VERSION}/{target}", + auth=AUTH, + data=s_file.open('rb').read() + ) + s_url = f"{URL}/api/packages/{USER}/generic/ormc-handouts/{VERSION}/{target}" - log(f"Published {title}") \ No newline at end of file + + log(f"Published {title}") + + new_index.append({ + "title": title, + "group": group, + "handout": h_url, + "solutions": s_url + }) + +requests.put( + f"{URL}/api/packages/{USER}/generic/{PACKAGE}/{VERSION}/index.json", + auth=AUTH, + data=json.dumps(new_index) +) \ No newline at end of file