Publish?
This commit is contained in:
parent
eb1ee2c2cb
commit
77a3a558b5
@ -18,21 +18,26 @@ SRC_DIR: Path = ROOT / "output"
|
|||||||
def log(msg):
|
def log(msg):
|
||||||
print(f"[PUBLISH.PY] {msg}")
|
print(f"[PUBLISH.PY] {msg}")
|
||||||
|
|
||||||
|
|
||||||
|
log(f"Version is {VERSION}")
|
||||||
|
log(f"Package is is {PACKAGE}")
|
||||||
log(f"Running in {ROOT}")
|
log(f"Running in {ROOT}")
|
||||||
if not ROOT.is_dir():
|
if not ROOT.is_dir():
|
||||||
log("Root is not a directory, cannot continue")
|
log("Root is not a directory, cannot continue")
|
||||||
exit(1)
|
exit(1)
|
||||||
|
|
||||||
log(f"Output dir is {SRC_DIR}")
|
log(f"Source dir is {SRC_DIR}")
|
||||||
if not SRC_DIR.exists():
|
if not SRC_DIR.exists():
|
||||||
log("Output dir doesn't exist, cannot continue")
|
log("Source dir doesn't exist, cannot continue")
|
||||||
exit(1)
|
exit(1)
|
||||||
|
|
||||||
IndexEntry = TypedDict(
|
def upload(data, target: string):
|
||||||
"IndexEntry",
|
requests.put(
|
||||||
{"title": str, "group": str, "handout_file": str, "solutions_file": str | None},
|
f"{URL}/api/packages/{USER}/generic/{PACKAGE}/{VERSION}/{target}",
|
||||||
)
|
auth=AUTH,
|
||||||
|
data=data
|
||||||
|
)
|
||||||
|
return f"{URL}/api/packages/{USER}/generic/ormc-handouts/{VERSION}/{target}"
|
||||||
|
|
||||||
index = SRC_DIR / "index.json"
|
index = SRC_DIR / "index.json"
|
||||||
with index.open("r") as f:
|
with index.open("r") as f:
|
||||||
@ -48,24 +53,16 @@ for handout in index:
|
|||||||
h_url = None
|
h_url = None
|
||||||
s_url = None
|
s_url = None
|
||||||
|
|
||||||
target = f"{group} - {title}.pdf"
|
h_url = upload(
|
||||||
requests.put(
|
h_file.open('rb').read(),
|
||||||
f"{URL}/api/packages/{USER}/generic/{PACKAGE}/{VERSION}/{target}",
|
f"{group} - {title}.pdf"
|
||||||
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:
|
if s_file is not None:
|
||||||
target = f"{group} - {title}.sols.pdf"
|
s_url = upload(
|
||||||
requests.put(
|
s_file.open('rb').read(),
|
||||||
f"{URL}/api/packages/{USER}/generic/{PACKAGE}/{VERSION}/{target}",
|
f"{group} - {title}.sols.pdf"
|
||||||
auth=AUTH,
|
|
||||||
data=s_file.open('rb').read()
|
|
||||||
)
|
)
|
||||||
s_url = f"{URL}/api/packages/{USER}/generic/ormc-handouts/{VERSION}/{target}"
|
|
||||||
|
|
||||||
|
|
||||||
log(f"Published {title}")
|
log(f"Published {title}")
|
||||||
|
|
||||||
@ -76,8 +73,7 @@ for handout in index:
|
|||||||
"solutions": s_url
|
"solutions": s_url
|
||||||
})
|
})
|
||||||
|
|
||||||
requests.put(
|
upload(
|
||||||
f"{URL}/api/packages/{USER}/generic/{PACKAGE}/{VERSION}/index.json",
|
json.dumps(new_index),
|
||||||
auth=AUTH,
|
"index.json"
|
||||||
data=json.dumps(new_index)
|
|
||||||
)
|
)
|
Loading…
x
Reference in New Issue
Block a user