This commit is contained in:
alexander
2026-01-22 21:14:16 +01:00
parent 8a26344e20
commit 24d0a9216a
21 changed files with 778 additions and 0 deletions

29
src/sources/util.py Normal file
View File

@@ -0,0 +1,29 @@
import hashlib
import requests
import datetime
import os
def get_datestring() -> str:
return datetime.datetime.now().strftime("%d.%m.%y")
def cache_cheatsheet(url, outdir: str) -> str | None:
r = requests.get(url)
if not r.ok and r.headers.get("Content-Type") != "application/pdf":
return None
data = r.content
hashdata = hashlib.sha256(data)
filesname = os.path.join("cache", f"{hashdata.hexdigest()}.pdf")
if not os.path.exists(os.path.join(outdir, "cache")):
os.mkdir(os.path.join(outdir, "cache"))
with open(os.path.join(outdir, filesname), "wb") as f:
f.write(data)
print("Saved file to", filesname)
return filesname