Make GWR ticket check use flask config
This commit is contained in:
parent
0465e5eddd
commit
3b89efa65f
|
@ -1,7 +1,6 @@
|
||||||
#!/usr/bin/python3
|
#!/usr/bin/python3
|
||||||
"""Update GWR advance ticket date cache."""
|
"""Update GWR advance ticket date cache."""
|
||||||
|
|
||||||
import configparser
|
|
||||||
import os.path
|
import os.path
|
||||||
import smtplib
|
import smtplib
|
||||||
import sys
|
import sys
|
||||||
|
@ -12,9 +11,7 @@ import requests
|
||||||
|
|
||||||
from agenda import gwr
|
from agenda import gwr
|
||||||
|
|
||||||
SMTP_HOST = "4angle.com"
|
config = __import__("config.default", fromlist=[""])
|
||||||
EMAIL = "edward@4angle.com"
|
|
||||||
NAME = "Edward Betts"
|
|
||||||
|
|
||||||
|
|
||||||
def send_mail(subject: str, body: str) -> None:
|
def send_mail(subject: str, body: str) -> None:
|
||||||
|
@ -22,33 +19,21 @@ def send_mail(subject: str, body: str) -> None:
|
||||||
msg = EmailMessage()
|
msg = EmailMessage()
|
||||||
|
|
||||||
msg["Subject"] = subject
|
msg["Subject"] = subject
|
||||||
msg["To"] = f"{NAME} <{EMAIL}>"
|
msg["To"] = f"{config.NAME} <{config.MAIL_TO}>"
|
||||||
msg["From"] = f"{NAME} <{EMAIL}>"
|
msg["From"] = f"{config.NAME} <{config.MAIL_FROM}>"
|
||||||
msg["Date"] = formatdate()
|
msg["Date"] = formatdate()
|
||||||
msg["Message-ID"] = make_msgid()
|
msg["Message-ID"] = make_msgid()
|
||||||
|
|
||||||
msg.set_content(body)
|
msg.set_content(body)
|
||||||
|
|
||||||
s = smtplib.SMTP(SMTP_HOST)
|
s = smtplib.SMTP(config.SMTP_HOST)
|
||||||
s.sendmail(EMAIL, [EMAIL], msg.as_string())
|
s.sendmail(config.MAIL_TO, [config.MAIL_TO], msg.as_string())
|
||||||
s.quit()
|
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:
|
def main() -> None:
|
||||||
"""Get date from web page and compare with existing."""
|
"""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_html = open(filename).read()
|
||||||
existing_date = gwr.extract_weekday_date(existing_html)
|
existing_date = gwr.extract_weekday_date(existing_html)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue