diff --git a/scripts/site_insights.py b/scripts/site_insights.py index f9edc0bfa..f10192b2e 100644 --- a/scripts/site_insights.py +++ b/scripts/site_insights.py @@ -41,6 +41,7 @@ import urllib.request from collections import defaultdict from dataclasses import dataclass from pathlib import Path +from typing import Any, cast sys.path.insert(0, os.path.dirname(__file__)) from common import github_token, load_database, load_emulator_profiles, run_cli @@ -123,7 +124,7 @@ def fetch_queries(start: dt.date, end: dt.date) -> list[Query]: return rows -def fetch_goatcounter(start: dt.date, end: dt.date) -> dict[str, list[tuple[str, int]]]: +def fetch_goatcounter(start: dt.date, end: dt.date) -> dict[str, Any]: """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}"} @@ -138,8 +139,8 @@ def fetch_goatcounter(start: dt.date, end: dt.date) -> dict[str, list[tuple[str, exclude.append(str(hit["path_id"])) if not answer.get("more"): break - 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) + refs = cast(dict, _get_json(f"{GOATCOUNTER}/stats/toprefs?{urllib.parse.urlencode({**span, 'limit': 50})}", auth)) + total = cast(dict, _get_json(f"{GOATCOUNTER}/stats/total?{urllib.parse.urlencode(span)}", auth)) # 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))