Fix broken GWR advance ticket check

This commit is contained in:
Edward Betts 2023-11-25 11:24:37 +00:00
parent 9185052092
commit df06402f19

View file

@ -4,6 +4,7 @@
import configparser import configparser
import os.path import os.path
import smtplib import smtplib
import sys
from email.message import EmailMessage from email.message import EmailMessage
from email.utils import formatdate, make_msgid from email.utils import formatdate, make_msgid
@ -35,7 +36,7 @@ def send_mail(subject: str, body: str) -> None:
def get_data_dir() -> str: def get_data_dir() -> str:
"""Read data dir from config.""" """Read data dir from config."""
config_filename = os.path.join(os.path.dirname(__file__), "..", "config") config_filename = os.path.join(os.path.dirname(__file__), "config")
assert os.path.exists(config_filename) assert os.path.exists(config_filename)
@ -57,6 +58,8 @@ def main() -> None:
new_date = gwr.extract_weekday_date(new_html) new_date = gwr.extract_weekday_date(new_html)
if existing_date == new_date: if existing_date == new_date:
if sys.stdin.isatty():
print("date has't changed:", existing_date)
return return
subject = "New GWR advance ticket booking date: {new_date}" subject = "New GWR advance ticket booking date: {new_date}"
@ -68,3 +71,7 @@ New date: {new_date}
Agenda: https://edwardbetts.com/agenda/ Agenda: https://edwardbetts.com/agenda/
""" """
send_mail(subject, body) send_mail(subject, body)
if __name__ == "__main__":
main()