chore: merge origin/main

This commit is contained in:
Abdessamad Derraz committed 2026-11-06 22:53:00 +01:00
commit 544df4326b
4 files changed
+10 -13

No files matched your search

+1 -1
View File
@@ -5018,7 +5018,7 @@ def _print_triage(
) -> bool:
"""Profiles ranked by drift, worst first. False when Ctrl-C cut the
scoring short: the ranking then covers the profiles scored."""
ranked: list[tuple] = []
ranked: list[tuple[int, ProfileReport, str]] = []
sampled = 0
progress = _Progress(len(reports), "scored", args.offline or len(reports) < 2)
complete = True
+6 -12
View File
@@ -123,15 +123,7 @@ def fetch_queries(start: dt.date, end: dt.date) -> list[Query]:
return rows
def _get_object(url: str, headers: dict[str, str] | None = None) -> dict:
"""A JSON answer that must be an object: GoatCounter's stats endpoints."""
answer = _get_json(url, headers)
if not isinstance(answer, dict):
raise ValueError(f"{url} answered {type(answer).__name__}, not an object")
return answer
def fetch_goatcounter(start: dt.date, end: dt.date) -> dict[str, list[tuple[str, int]] | int]:
def fetch_goatcounter(start: dt.date, end: dt.date) -> dict:
"""Paths and events with their visit counts, and the referring domains."""
token = (CONFIG / "goatcounter-api-token.txt").read_text(encoding="utf-8").strip()
auth = {"Authorization": f"Bearer {token}"}
@@ -140,14 +132,16 @@ def fetch_goatcounter(start: dt.date, end: dt.date) -> dict[str, list[tuple[str,
exclude: list[str] = []
while True:
params = urllib.parse.urlencode({**span, "limit": 100, "exclude_paths": ",".join(exclude)})
answer = _get_object(f"{GOATCOUNTER}/stats/hits?{params}", auth)
answer = _get_json(f"{GOATCOUNTER}/stats/hits?{params}", auth)
for hit in answer.get("hits", []):
hits.append((hit["path"] + (" [404]" if hit.get("title") == "404" else ""), int(hit["count"])))
exclude.append(str(hit["path_id"]))
if not answer.get("more"):
break
refs = _get_object(f"{GOATCOUNTER}/stats/toprefs?{urllib.parse.urlencode({**span, 'limit': 50})}", auth)
total = _get_object(f"{GOATCOUNTER}/stats/total?{urllib.parse.urlencode(span)}", auth)
refs = _get_json(f"{GOATCOUNTER}/stats/toprefs?{urllib.parse.urlencode({**span, 'limit': 50})}", auth)
total = _get_json(f"{GOATCOUNTER}/stats/total?{urllib.parse.urlencode(span)}", auth)
if not isinstance(refs, dict) or not isinstance(total, dict):
raise SystemExit("GoatCounter answered with something other than an object")
# An action carries no referrer, and GoatCounter files it as a direct
# visit: 592 of the first day's 1,145 "direct" were clicks.
events = int(total.get("total_events", 0))