From 002771908a23299c9aea7acebb1f1462767f0558 Mon Sep 17 00:00:00 2001 From: Ari Archer Date: Sun, 15 Dec 2024 16:44:31 +0200 Subject: [PATCH] update @ Sun Dec 15 16:44:31 EET 2024 Signed-off-by: Ari Archer --- .gitignore | 1 + media/media.json | 2 +- scripts/blog.py | 18 ++++++++++++++++-- 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index bec358a..6cd4b8f 100644 --- a/.gitignore +++ b/.gitignore @@ -15,3 +15,4 @@ venv/ /sitemap.xml /robots.txt /stats/ +/licenses.json diff --git a/media/media.json b/media/media.json index fcb0099..a09574f 100644 --- a/media/media.json +++ b/media/media.json @@ -6,7 +6,7 @@ "alt": "A black cat sitting in a box peacefully", "purpose": "To have a cute cat who looks over blog.ari.lt", "title": "Tina in a box (2019-2020, I think)", - "license": "CC-BY-SA", + "license": "CC-BY-SA-1.0", "credit": "Ari Archer", "ext": "jpeg", "mime": "image/jpeg", diff --git a/scripts/blog.py b/scripts/blog.py index 4b86525..9e332ce 100755 --- a/scripts/blog.py +++ b/scripts/blog.py @@ -439,6 +439,7 @@ STATS_TEMPLATE: typing.Final[str] = ( ) if NCI: + import requests import http.server import magic @@ -447,6 +448,7 @@ if NCI: else: pyfzf: typing.Any = None http: typing.Any = None + requests: typing.Any = None magic: typing.Any = None Image: typing.Any = None @@ -570,7 +572,7 @@ def select_medias(type: typing.Optional[str] = None) -> tuple[str, ...]: lambda opt: opt.split("|", maxsplit=1)[0].strip(), select_multi( tuple( - f"{mdx} | {mdy['type']}, {mdy['alt']} for {mdy['purpose']} | {mdy['title']}, {mdy['credit']}" + f"{mdx} | {mdy['type']}, {mdy['alt']} for {mdy['purpose']} | {mdy['title']}, {mdy['credit']} ({mdy['license']})" for mdx, mdy in MEDIA_INDEX.items() if mdy["type"] == type ) @@ -1720,6 +1722,17 @@ def media(config: dict[str, typing.Any]) -> int: assert config is config, "Unused" + if os.path.exists("licenses.json"): + with open("licenses.json", "r") as fp: + licenses: tuple[str, ...] = json.load(fp) + else: + lnew("fetching SPDX license IDs") + + licenses = tuple(license["licenseId"] for license in requests.get("https://raw.githubusercontent.com/spdx/license-list-data/master/json/licenses.json").json()["licenses"]) + + with open("licenses.json", "w") as fp: + json.dump(licenses, fp) + path: str = iinput("media path") path = os.path.expanduser(path) @@ -1728,7 +1741,8 @@ def media(config: dict[str, typing.Any]) -> int: purpose: str = iinput("media purpose") title: str = iinput("media title") - license: str = iinput("media license (SPDX)") + license: str = ", ".join(select_multi(licenses)) + credit: str = iinput("media credit") # MIME stuff