58 lines
1.4 KiB
Python
58 lines
1.4 KiB
Python
from typing import TypedDict
|
|
from pathlib import Path
|
|
import requests
|
|
import shutil
|
|
import json
|
|
import os
|
|
from requests.auth import HTTPBasicAuth
|
|
|
|
URL="https://git.betalupi.com"
|
|
USER = os.environ['USER']
|
|
PACKAGE = "ormc-handouts"
|
|
VERSION = os.environ['VERSION']
|
|
AUTH = HTTPBasicAuth(USER, os.environ['PUBLISH_KEY'])
|
|
|
|
ROOT: Path = Path(os.getcwd())
|
|
SRC_DIR: Path = ROOT / "output"
|
|
|
|
def log(msg):
|
|
print(f"[PUBLISH.PY] {msg}")
|
|
|
|
log(f"Running in {ROOT}")
|
|
if not ROOT.is_dir():
|
|
log("Root is not a directory, cannot continue")
|
|
exit(1)
|
|
|
|
log(f"Output dir is {SRC_DIR}")
|
|
if not SRC_DIR.exists():
|
|
log("Output dir doesn't exist, cannot continue")
|
|
exit(1)
|
|
|
|
IndexEntry = TypedDict(
|
|
"IndexEntry",
|
|
{"title": str, "group": str, "handout_file": str, "solutions_file": str | None},
|
|
)
|
|
|
|
|
|
index = SRC_DIR / "index.json"
|
|
with index.open("r") as f:
|
|
index = json.load(f)
|
|
|
|
for handout in index:
|
|
title = handout["title"]
|
|
group = handout["group"]
|
|
h_file = SRC_DIR/handout["handout_file"]
|
|
s_file = SRC_DIR/handout["handout_file"]
|
|
|
|
target = f"{group} - {title}.pdf"
|
|
requests.put(
|
|
f"{URL}/api/packages/{USER}/generic/{PACKAGE}/{VERSION}/{target}",
|
|
auth=AUTH, data=h_file.open('rb').read())
|
|
|
|
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())
|
|
|
|
log(f"Published {title}") |