commit - c441e0c63e9336b63c4266681ff508d147a732e6
commit + 1719b036fc8676d9b8d367b342df0f39cb2a1565
blob - ead84456eb0e78a951a0303ce7fbd1a310257c62
blob + eb13d14bcd95f211d073eeb86e48d0d1a432961e
--- .gitignore
+++ .gitignore
**/*.swp
+.local/
blob - /dev/null
blob + ec84c8db984e928f23b708f77a7e84ffba62a31d (mode 644)
--- /dev/null
+++ lonk.py
+from json import loads as json_loads
+from pathlib import Path
+from urllib.parse import urlencode, urlunsplit
+from urllib.request import urlopen
+
+
+_TOKEN = (Path(__file__).parent / ".local" / "token").read_text(encoding="utf8")
+
+def _load_from(action, page, c=None):
+ query = {"action": action, "page": page, "token": _TOKEN}
+ if c is not None:
+ query["c"] = c
+
+ url = urlunsplit(("https", "honk.any-key.press", "api", urlencode(query), ""))
+ with urlopen(url, timeout=15) as f:
+ return json_loads(f.read().decode("utf8"))
+
+
+collected = {}
+
+
+for honk in reversed(_load_from(action="gethonks", page="home")["honks"]):
+ convoy = honk["Convoy"]
+ if convoy in collected:
+ continue
+ if honk.get("RID"):
+ answer = _load_from(action="gethonks", page="convoy", c=convoy)
+ for honk_in_convoy in _load_from(action="gethonks", page="convoy", c=convoy)["honks"]:
+ if not honk_in_convoy.get("RID"):
+ collected[convoy] = honk_in_convoy
+ break
+ else:
+ collected[convoy] = honk
+
+
+def _format_honk(honk):
+ lines = [honk.get("Oondle") or honk["Handle"], honk["XID"], honk["Noise"]]
+ for donk in (honk.get("Donks") or []):
+ lines.append(donk["URL"])
+ desc = donk.get("Desc")
+ if desc:
+ lines.append(desc)
+ return "\n".join(lines)
+
+
+print("\n\n".join(_format_honk(honk) for honk in reversed(collected.values())))