Make GWR ticket check use flask config

This commit is contained in:
Edward Betts 2023-12-07 19:06:48 +00:00
parent 0465e5eddd
commit 3b89efa65f

View file

@ -1,7 +1,6 @@
#!/usr/bin/python3
"""Update GWR advance ticket date cache."""
import configparser
import os.path
import smtplib
import sys
@ -12,9 +11,7 @@ import requests
from agenda import gwr
SMTP_HOST = "4angle.com"
EMAIL = "edward@4angle.com"
NAME = "Edward Betts"
config = __import__("config.default", fromlist=[""])
def send_mail(subject: str, body: str) -> None:
@ -22,33 +19,21 @@ def send_mail(subject: str, body: str) -> None:
msg = EmailMessage()
msg["Subject"] = subject
msg["To"] = f"{NAME} <{EMAIL}>"
msg["From"] = f"{NAME} <{EMAIL}>"
msg["To"] = f"{config.NAME} <{config.MAIL_TO}>"
msg["From"] = f"{config.NAME} <{config.MAIL_FROM}>"
msg["Date"] = formatdate()
msg["Message-ID"] = make_msgid()
msg.set_content(body)
s = smtplib.SMTP(SMTP_HOST)
s.sendmail(EMAIL, [EMAIL], msg.as_string())
s = smtplib.SMTP(config.SMTP_HOST)
s.sendmail(config.MAIL_TO, [config.MAIL_TO], msg.as_string())
s.quit()
def get_data_dir() -> str:
"""Read data dir from config."""
config_filename = os.path.join(os.path.dirname(__file__), "config")
assert os.path.exists(config_filename)
config = configparser.ConfigParser()
config.read(config_filename)
return config.get("data", "dir")
def main() -> None:
"""Get date from web page and compare with existing."""
filename = os.path.join(get_data_dir(), "advance-tickets.html")
filename = os.path.join(config.DATA_DIR, "advance-tickets.html")
existing_html = open(filename).read()
existing_date = gwr.extract_weekday_date(existing_html)