Fix broken GWR advance ticket check
This commit is contained in:
parent
9185052092
commit
8027782601
|
@ -8,6 +8,7 @@ from email.message import EmailMessage
|
||||||
from email.utils import formatdate, make_msgid
|
from email.utils import formatdate, make_msgid
|
||||||
|
|
||||||
import requests
|
import requests
|
||||||
|
import sys
|
||||||
|
|
||||||
from agenda import gwr
|
from agenda import gwr
|
||||||
|
|
||||||
|
@ -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()
|
||||||
|
|
Loading…
Reference in a new issue