mirror of
https://github.com/Abdess/retroarch_system.git
synced 2026-11-26 11:28:51 -06:00
refactor: move ten command helpers into packages
This commit is contained in:
1 parent
6d21a98342
commit
19681a3735
22 files changed
+218
-191
No files matched your search
+1
-26
@@ -25,32 +25,7 @@ import sys
|
||||
from pathlib import Path
|
||||
|
||||
sys.path.insert(0, os.path.dirname(__file__))
|
||||
from core import upstream
|
||||
from sitegen.agents import INDEXNOW_FILE, INDEXNOW_KEY, SITE
|
||||
|
||||
HOST = "abdess.github.io"
|
||||
# What one IndexNow request accepts.
|
||||
MAX_URLS = 10_000
|
||||
USER_AGENT = "retrobios-indexnow"
|
||||
|
||||
|
||||
def live_digests(url: str = f"{SITE}digests.json") -> dict[str, str]:
|
||||
"""The digests the live site serves. None yet (the first deploy that
|
||||
writes them) is an empty map: every page is new."""
|
||||
body = upstream.fetch_body(url, timeout=60, user_agent=USER_AGENT)
|
||||
return {} if body is None else json.loads(body.decode("utf-8"))
|
||||
|
||||
|
||||
def changed_urls(new: dict[str, str], old: dict[str, str]) -> list[str]:
|
||||
"""Pages added, changed or removed between two digest maps."""
|
||||
return sorted(url for url in new.keys() | old.keys() if new.get(url) != old.get(url))
|
||||
|
||||
|
||||
def payload(urls: list[str]) -> dict:
|
||||
if len(urls) > MAX_URLS:
|
||||
raise SystemExit(f"error: {len(urls)} changed pages, one request takes {MAX_URLS}")
|
||||
return {"host": HOST, "key": INDEXNOW_KEY, "keyLocation": f"{SITE}{INDEXNOW_FILE}",
|
||||
"urlList": urls}
|
||||
from sitegen.indexnow import changed_urls, live_digests, payload
|
||||
|
||||
|
||||
def main() -> int:
|
||||
|
||||
Reference in new issue
Block a user