GWR ticket date mail shows weekends
GWR advance ticket change email now shows Saturdays and Sundays in addition to Weekdays. Switched from ISO dates to human readable dates. Closes: #177
This commit is contained in:
parent
197f6e5bfd
commit
488ecf8b71
39
update.py
39
update.py
|
@ -54,26 +54,49 @@ def update_gwr_advance_ticket_date(config: flask.config.Config) -> None:
|
|||
"""Update GWR advance ticket date cache."""
|
||||
filename = os.path.join(config["DATA_DIR"], "advance-tickets.html")
|
||||
existing_html = open(filename).read()
|
||||
existing_date = agenda.gwr.extract_weekday_date(existing_html)
|
||||
|
||||
existing_dates = agenda.gwr.extract_dates(existing_html)
|
||||
assert existing_dates
|
||||
assert list(existing_dates.keys()) == ["Weekdays", "Saturdays", "Sundays"]
|
||||
|
||||
new_html = requests.get(agenda.gwr.url).text
|
||||
open(filename, "w").write(new_html)
|
||||
|
||||
new_date = agenda.gwr.extract_weekday_date(new_html)
|
||||
new_dates = agenda.gwr.extract_dates(new_html)
|
||||
assert new_dates
|
||||
assert list(new_dates.keys()) == ["Weekdays", "Saturdays", "Sundays"]
|
||||
|
||||
if existing_date == new_date:
|
||||
if existing_dates == new_dates:
|
||||
if sys.stdin.isatty():
|
||||
print("date has't changed:", existing_date)
|
||||
print(filename)
|
||||
print(agenda.gwr.url)
|
||||
print("dates haven't changed:", existing_dates)
|
||||
return
|
||||
|
||||
subject = f"New GWR advance ticket booking date: {new_date}"
|
||||
body = f"""Old date: {existing_date}
|
||||
New date: {new_date}
|
||||
open(filename, "w").write(new_html)
|
||||
|
||||
subject = (
|
||||
"New GWR advance ticket booking date: "
|
||||
+ f'{new_dates["Weekdays"].strftime("%d %b %Y")} (Weekdays)'
|
||||
)
|
||||
body = f"""
|
||||
{"\n".join(f'{key}: {when.strftime("%d %b %Y")}' for key, when in new_dates.items())}
|
||||
|
||||
{agenda.gwr.url}
|
||||
|
||||
Agenda: https://edwardbetts.com/agenda/
|
||||
"""
|
||||
|
||||
if sys.stdin.isatty():
|
||||
print(filename)
|
||||
print(agenda.gwr.url)
|
||||
print()
|
||||
print("dates have changed")
|
||||
print("old:", existing_dates)
|
||||
print("new:", new_dates)
|
||||
print()
|
||||
print(subject)
|
||||
print(body)
|
||||
|
||||
agenda.mail.send_mail(config, subject, body)
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue