Commit 8adf0e15ec

8adf0e15ecc2aaaae8aba7bd53cf0f411c4a46f1

parent: 392140ea1d

Unsigned

Alicia Sykes <alicia@omg.lol> · 2026-06-07 22:00 UTC

Update lib scripts to use new API

Layout: unified · split

.github/workflows/pr-check.yml +1
@@ -152,6 +152,7 @@ jobs:
152152 continue-on-error: true
153153 env:
154154 GITHUB_TOKEN: ${{ github.token }}
155 API_TOKEN: ${{ secrets.API_TOKEN }}
155156 run: python lib/checks/make-info-stats.py
156157 - name: Check for repo stats
157158 if: always()
lib/checks/make-info-stats.py +23 −14
@@ -22,6 +22,7 @@ import argparse
2222import json
2323import logging
2424import os
25import re
2526import sys
2627from datetime import datetime, timezone
2728from urllib.parse import urlparse
@@ -43,10 +44,8 @@ RESTRICTIVE_LICENSES = {
4344
4445SESSION = utils.make_session(user_agent=USER_AGENT)
4546
46SITE_INFO_URL = "https://site-info-fetch.as93.workers.dev"
47ANDROID_API_URL = "https://android-app-privacy.as93.net"
48IOS_API_URL = "https://ios-app-info.as93.net"
49TOSDR_API_URL = "https://privacy-policies.as93.workers.dev"
47API_URL = os.environ.get("API_URL", "https://api.awesome-privacy.xyz").rstrip("/")
48API_TOKEN = os.environ.get("API_TOKEN", "")
5049
5150GREEN, ORANGE, RED, BLUE, WHITE = "\U0001f7e2", "\U0001f7e0", "\U0001f534", "\U0001f535", "\u26aa"
5251
@@ -62,6 +61,12 @@ def _api_get(url, params=None, timeout=TIMEOUT, headers=None):
6261 return None
6362
6463
64def _enrich_get(path, params=None, timeout=TIMEOUT):
65 """GET an enrichment endpoint on the unified API, adding auth when configured."""
66 headers = {"Authorization": f"Bearer {API_TOKEN}"} if API_TOKEN else None
67 return _api_get(f"{API_URL}/v1/enrich/{path}", params=params, headers=headers, timeout=timeout)
68
69
6570def relative_time(iso_str):
6671 """Convert ISO timestamp to human-readable relative time, or None."""
6772 if not iso_str:
@@ -287,8 +292,8 @@ def grade_stats(data):
287292
288293
289294def fetch_website_data(url):
290 """Fetch site info from the worker API."""
291 return _api_get(SITE_INFO_URL, params={"url": url}, timeout=15)
295 """Fetch site info from the unified API."""
296 return _enrich_get("website", params={"url": url}, timeout=15)
292297
293298
294299def check_security_txt(url):
@@ -400,7 +405,7 @@ def grade_website_stats(data, url, has_security_txt):
400405def fetch_android_data(package_id):
401406 """Fetch Android app privacy data."""
402407 package_id = package_id.split("id=")[-1] if "id=" in package_id else package_id
403 data = _api_get(f"{ANDROID_API_URL}/{package_id}")
408 data = _enrich_get(f"android/{package_id}")
404409 return data if data and not data.get("error") else None
405410
406411
@@ -430,11 +435,15 @@ def grade_android_stats(data):
430435
431436
432437def fetch_ios_data(app_url):
433 """Fetch iOS app info."""
434 # The API requires a country code in the URL path — insert /us/ if missing
435 if app_url and "apps.apple.com/app/" in app_url:
436 app_url = app_url.replace("apps.apple.com/app/", "apps.apple.com/us/app/", 1)
437 return _api_get(IOS_API_URL, params={"appStoreUrl": app_url})
438 """Fetch iOS app info, extracting the numeric id and country from the store URL."""
439 if not app_url:
440 return None
441 id_match = re.search(r"id(\d+)", app_url)
442 if not id_match:
443 return None
444 country_match = re.search(r"apps\.apple\.com/([a-z]{2})/", app_url)
445 country = country_match.group(1) if country_match else "us"
446 return _enrich_get(f"ios/{id_match.group(1)}", params={"country": country})
438447
439448
440449def grade_ios_stats(data):
@@ -457,13 +466,13 @@ def grade_ios_stats(data):
457466
458467def fetch_tosdr_data(service_id):
459468 """Fetch ToS;DR privacy policy data."""
460 return _api_get(f"{TOSDR_API_URL}/{service_id}")
469 return _enrich_get(f"privacy/{service_id}")
461470
462471
463472def grade_tosdr_stats(data):
464473 """Grade ToS;DR privacy policy stats."""
465474 stats = []
466 params = data.get("parameters") or {}
475 params = data or {}
467476
468477 rating = params.get("rating")
469478 if not rating: