fix: add sec-fetch headers and fallback to notification listing on 403
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -22,6 +22,7 @@ NTFY_TOKEN = os.environ.get("NTFY_TOKEN", "") # optional, if your ntfy requir
|
|||||||
STATE_FILE = os.environ.get("STATE_FILE", "last_seen.txt")
|
STATE_FILE = os.environ.get("STATE_FILE", "last_seen.txt")
|
||||||
|
|
||||||
ZIPAIR_SITEMAP = "https://www.zipair.net/sitemap.xml"
|
ZIPAIR_SITEMAP = "https://www.zipair.net/sitemap.xml"
|
||||||
|
ZIPAIR_NOTIF_LIST = "https://www.zipair.net/en/notification"
|
||||||
ZIPAIR_NOTIF = "https://www.zipair.net/en/notification/{id}"
|
ZIPAIR_NOTIF = "https://www.zipair.net/en/notification/{id}"
|
||||||
|
|
||||||
# Keywords that must ALL appear (case-insensitive) in a notification page
|
# Keywords that must ALL appear (case-insensitive) in a notification page
|
||||||
@@ -36,9 +37,14 @@ HEADERS = {
|
|||||||
"Chrome/124.0.0.0 Safari/537.36"
|
"Chrome/124.0.0.0 Safari/537.36"
|
||||||
),
|
),
|
||||||
"Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8",
|
"Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8",
|
||||||
"Accept-Language": "en-US,en;q=0.9",
|
"Accept-Language": "en-US,en;q=0.9,ja;q=0.8",
|
||||||
"Accept-Encoding": "gzip, deflate, br",
|
"Accept-Encoding": "gzip, deflate, br",
|
||||||
"Connection": "keep-alive",
|
"Connection": "keep-alive",
|
||||||
|
"Referer": "https://www.zipair.net/",
|
||||||
|
"Sec-Fetch-Dest": "document",
|
||||||
|
"Sec-Fetch-Mode": "navigate",
|
||||||
|
"Sec-Fetch-Site": "same-origin",
|
||||||
|
"Upgrade-Insecure-Requests": "1",
|
||||||
}
|
}
|
||||||
|
|
||||||
# ── Helpers ─────────────────────────────────────────────────────────────────
|
# ── Helpers ─────────────────────────────────────────────────────────────────
|
||||||
@@ -67,12 +73,22 @@ def get_notification_ids_from_sitemap() -> list[int]:
|
|||||||
"""Parse the ZIPAIR sitemap and return all notification IDs found."""
|
"""Parse the ZIPAIR sitemap and return all notification IDs found."""
|
||||||
print("Fetching sitemap …")
|
print("Fetching sitemap …")
|
||||||
xml = fetch(ZIPAIR_SITEMAP)
|
xml = fetch(ZIPAIR_SITEMAP)
|
||||||
if not xml:
|
if xml:
|
||||||
print(" Sitemap unavailable.", file=sys.stderr)
|
|
||||||
return []
|
|
||||||
ids = [int(m) for m in re.findall(r"/notification/(\d+)", xml)]
|
ids = [int(m) for m in re.findall(r"/notification/(\d+)", xml)]
|
||||||
|
if ids:
|
||||||
ids = sorted(set(ids))
|
ids = sorted(set(ids))
|
||||||
print(f" Found {len(ids)} notification IDs in sitemap (max={ids[-1] if ids else 'n/a'})")
|
print(f" Found {len(ids)} notification IDs in sitemap (max={ids[-1]})")
|
||||||
|
return ids
|
||||||
|
|
||||||
|
# Fallback: scrape the notification listing page
|
||||||
|
print(" Sitemap unavailable, trying notification listing page …")
|
||||||
|
html = fetch(ZIPAIR_NOTIF_LIST)
|
||||||
|
if not html:
|
||||||
|
print(" Notification listing page also unavailable.", file=sys.stderr)
|
||||||
|
return []
|
||||||
|
ids = [int(m) for m in re.findall(r"/notification/(\d+)", html)]
|
||||||
|
ids = sorted(set(ids))
|
||||||
|
print(f" Found {len(ids)} notification IDs from listing page (max={ids[-1] if ids else 'n/a'})")
|
||||||
return ids
|
return ids
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user