Commit 8adf0e15ec
Unsigned
Layout: unified · split
.github/workflows/pr-check.yml +1
| @@ -152,6 +152,7 @@ jobs: | |||
| 152 | continue-on-error: true | 152 | continue-on-error: true |
| 153 | env: | 153 | env: |
| 154 | GITHUB_TOKEN: ${{ github.token }} | 154 | GITHUB_TOKEN: ${{ github.token }} |
| 155 | API_TOKEN: ${{ secrets.API_TOKEN }} | ||
| 155 | run: python lib/checks/make-info-stats.py | 156 | run: python lib/checks/make-info-stats.py |
| 156 | - name: Check for repo stats | 157 | - name: Check for repo stats |
| 157 | if: always() | 158 | if: always() |
lib/checks/make-info-stats.py +23 −14
| @@ -22,6 +22,7 @@ import argparse | |||
| 22 | import json | 22 | import json |
| 23 | import logging | 23 | import logging |
| 24 | import os | 24 | import os |
| 25 | import re | ||
| 25 | import sys | 26 | import sys |
| 26 | from datetime import datetime, timezone | 27 | from datetime import datetime, timezone |
| 27 | from urllib.parse import urlparse | 28 | from urllib.parse import urlparse |
| @@ -43,10 +44,8 @@ RESTRICTIVE_LICENSES = { | |||
| 43 | 44 | ||
| 44 | SESSION = utils.make_session(user_agent=USER_AGENT) | 45 | SESSION = utils.make_session(user_agent=USER_AGENT) |
| 45 | 46 | ||
| 46 | SITE_INFO_URL = "https://site-info-fetch.as93.workers.dev" | 47 | API_URL = os.environ.get("API_URL", "https://api.awesome-privacy.xyz").rstrip("/") |
| 47 | ANDROID_API_URL = "https://android-app-privacy.as93.net" | 48 | API_TOKEN = os.environ.get("API_TOKEN", "") |
| 48 | IOS_API_URL = "https://ios-app-info.as93.net" | ||
| 49 | TOSDR_API_URL = "https://privacy-policies.as93.workers.dev" | ||
| 50 | 49 | ||
| 51 | GREEN, ORANGE, RED, BLUE, WHITE = "\U0001f7e2", "\U0001f7e0", "\U0001f534", "\U0001f535", "\u26aa" | 50 | GREEN, ORANGE, RED, BLUE, WHITE = "\U0001f7e2", "\U0001f7e0", "\U0001f534", "\U0001f535", "\u26aa" |
| 52 | 51 | ||
| @@ -62,6 +61,12 @@ def _api_get(url, params=None, timeout=TIMEOUT, headers=None): | |||
| 62 | return None | 61 | return None |
| 63 | 62 | ||
| 64 | 63 | ||
| 64 | def _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 | |||
| 65 | def relative_time(iso_str): | 70 | def relative_time(iso_str): |
| 66 | """Convert ISO timestamp to human-readable relative time, or None.""" | 71 | """Convert ISO timestamp to human-readable relative time, or None.""" |
| 67 | if not iso_str: | 72 | if not iso_str: |
| @@ -287,8 +292,8 @@ def grade_stats(data): | |||
| 287 | 292 | ||
| 288 | 293 | ||
| 289 | def fetch_website_data(url): | 294 | def fetch_website_data(url): |
| 290 | """Fetch site info from the worker API.""" | 295 | """Fetch site info from the unified API.""" |
| 291 | return _api_get(SITE_INFO_URL, params={"url": url}, timeout=15) | 296 | return _enrich_get("website", params={"url": url}, timeout=15) |
| 292 | 297 | ||
| 293 | 298 | ||
| 294 | def check_security_txt(url): | 299 | def check_security_txt(url): |
| @@ -400,7 +405,7 @@ def grade_website_stats(data, url, has_security_txt): | |||
| 400 | def fetch_android_data(package_id): | 405 | def fetch_android_data(package_id): |
| 401 | """Fetch Android app privacy data.""" | 406 | """Fetch Android app privacy data.""" |
| 402 | package_id = package_id.split("id=")[-1] if "id=" in package_id else package_id | 407 | 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}") |
| 404 | return data if data and not data.get("error") else None | 409 | return data if data and not data.get("error") else None |
| 405 | 410 | ||
| 406 | 411 | ||
| @@ -430,11 +435,15 @@ def grade_android_stats(data): | |||
| 430 | 435 | ||
| 431 | 436 | ||
| 432 | def fetch_ios_data(app_url): | 437 | def fetch_ios_data(app_url): |
| 433 | """Fetch iOS app info.""" | 438 | """Fetch iOS app info, extracting the numeric id and country from the store URL.""" |
| 434 | # The API requires a country code in the URL path — insert /us/ if missing | 439 | if not app_url: |
| 435 | if app_url and "apps.apple.com/app/" in app_url: | 440 | return None |
| 436 | app_url = app_url.replace("apps.apple.com/app/", "apps.apple.com/us/app/", 1) | 441 | id_match = re.search(r"id(\d+)", app_url) |
| 437 | return _api_get(IOS_API_URL, params={"appStoreUrl": 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}) | ||
| 438 | 447 | ||
| 439 | 448 | ||
| 440 | def grade_ios_stats(data): | 449 | def grade_ios_stats(data): |
| @@ -457,13 +466,13 @@ def grade_ios_stats(data): | |||
| 457 | 466 | ||
| 458 | def fetch_tosdr_data(service_id): | 467 | def fetch_tosdr_data(service_id): |
| 459 | """Fetch ToS;DR privacy policy data.""" | 468 | """Fetch ToS;DR privacy policy data.""" |
| 460 | return _api_get(f"{TOSDR_API_URL}/{service_id}") | 469 | return _enrich_get(f"privacy/{service_id}") |
| 461 | 470 | ||
| 462 | 471 | ||
| 463 | def grade_tosdr_stats(data): | 472 | def grade_tosdr_stats(data): |
| 464 | """Grade ToS;DR privacy policy stats.""" | 473 | """Grade ToS;DR privacy policy stats.""" |
| 465 | stats = [] | 474 | stats = [] |
| 466 | params = data.get("parameters") or {} | 475 | params = data or {} |
| 467 | 476 | ||
| 468 | rating = params.get("rating") | 477 | rating = params.get("rating") |
| 469 | if not rating: | 478 | if not rating: |