Suppress GWR busy-page error emails and add regression tests

This commit is contained in:
Edward Betts 2026-09-20 16:11:14 +01:00
parent 5aee8f5720
commit e75acc3364
2 changed files with 67 additions and 2 deletions

View file

@ -14,6 +14,7 @@ from time import time
# old authlib.jose module. Importing authlib.deprecate first lets us insert our
# "ignore" filter at position 0 so it wins the ordering race.
import authlib.deprecate # noqa: E402 — must precede the filter below
warnings.filterwarnings("ignore", message="authlib.jose module is deprecated")
import deepdiff
@ -85,13 +86,20 @@ def update_gwr_advance_ticket_date(config: flask.config.Config) -> None:
existing_html = open(filename).read()
existing_dates = agenda.gwr.extract_dates(existing_html)
assert existing_dates
assert list(existing_dates.keys()) == ["Weekdays", "Saturdays", "Sundays"]
if existing_dates:
assert existing_dates
assert list(existing_dates.keys()) == ["Weekdays", "Saturdays", "Sundays"]
new_html = requests.get(agenda.gwr.url).text
new_dates = agenda.gwr.extract_dates(new_html)
if not new_dates:
busy_message = (
"We are sorry that we cannot show you the page you were looking for. "
"Our website is extremely busy at the moment"
)
if busy_message in " ".join(new_html.split()):
return
subject = "Error parsing GWR advance ticket booking dates"
body = new_html
agenda.mail.send_mail(config, subject, body)