diff --git a/check.py b/check.py index efcfa08..4b9349f 100755 --- a/check.py +++ b/check.py @@ -121,7 +121,9 @@ def normalize_url(url: str) -> str: return urlunparse(parsed_url._replace(netloc=normalized_netloc)) -def check_conference(name: str, src_url: str, year: int) -> tuple[bool, str]: +def check_conference( + name: str, src_url: str, year: int +) -> tuple[bool, str, str | None]: """Check if conference is live.""" url = src_url.format(year=year) past_url = src_url.format(year=year - 1) @@ -129,7 +131,7 @@ def check_conference(name: str, src_url: str, year: int) -> tuple[bool, str]: # SotM Baltics has an invalid TLS certificate, but we don't care r = s.get(url, verify=False) except requests.exceptions.ConnectionError: - return (False, "connection refused") + return (False, "connection refused", None) not_here = find_not_here_message(r.text) if ( @@ -137,15 +139,12 @@ def check_conference(name: str, src_url: str, year: int) -> tuple[bool, str]: and 'http-equiv="refresh"' in r.text and str(year) not in r.text ): - return (False, "redirect to URL without year") - - if str(year) not in r.url: - return (False, "redirect to URL without year") + return (False, "redirect to URL without year", r.url) if normalize_url(r.url) == normalize_url(past_url): - return (False, "redirect to previous year") + return (False, "redirect to previous year", r.url) - return (False, not_here) if not_here else (True, get_title(r.text)) + return (False, not_here, r.url) if not_here else (True, get_title(r.text), r.url) def send_mail(subject: str, body: str) -> None: @@ -174,10 +173,15 @@ def send_mail(subject: str, body: str) -> None: def check_conference_web_site(name: str, src_url: str, year: int) -> bool: """Check if an individual web site is live.""" assert "{year}" in src_url - live, msg = check_conference(name, src_url, year) + live, msg, redirect_to_url = check_conference(name, src_url, year) url = src_url.format(year=year) if live: - body = f"{name}\n{url}\nWeb page title: {msg}" + if redirect_to_url == url: + body = f"{name}\n{url}\nWeb page title: {msg}" + else: + body = f"""{name} +{url} redirects to {redirect_to_url} +Web page title: {msg}""" send_mail(f"Conference site live: {name} - {year}", body) return live