diff --git a/check.py b/check.py index ca78184..6b08255 100755 --- a/check.py +++ b/check.py @@ -2,9 +2,11 @@ """Check if conference websites are live.""" +import configparser import os import re import smtplib +import typing import warnings from datetime import date from email.mime.text import MIMEText @@ -13,10 +15,16 @@ from email.utils import formatdate, make_msgid import requests import yaml from requests.adapters import HTTPAdapter -from urllib3.exceptions import InsecureRequestWarning -from urllib3.util.url import parse_url +from urllib3.exceptions import InsecureRequestWarning # type: ignore +from urllib3.util.url import parse_url # type: ignore -from conference import LiveConference, config, load_yaml + +class LiveConference(typing.TypedDict): + """Live conference.""" + + conference: str + year: int + live: date class AbsoluteDNSAdapter(HTTPAdapter): @@ -28,7 +36,6 @@ class AbsoluteDNSAdapter(HTTPAdapter): # Append a dot to the hostname if it's not already there. hostname = parsed_url.host - assert hostname if not hostname.endswith("."): hostname += "." @@ -43,6 +50,16 @@ class AbsoluteDNSAdapter(HTTPAdapter): return super().send(request, **kwargs) +config_file_path = os.path.expanduser( + os.path.join( + os.getenv("XDG_CONFIG_HOME", "~/.config"), "conference-check", "config" + ) +) + +config = configparser.ConfigParser() +config.read(os.path.expanduser(config_file_path)) + + # Suppress only the single InsecureRequestWarning from urllib3 warnings.filterwarnings("ignore", category=InsecureRequestWarning) @@ -78,7 +95,6 @@ not_here_list = [ "Wikimedia Error", "The page you requested could not be found", "Ooops! Could Not Find It", - "OpenStreetMap Authentication Proxy", ] @@ -128,6 +144,13 @@ def send_mail(subject: str, body: str) -> None: s.quit() +def load_yaml(name: str) -> typing.Any: + """Load YAML.""" + filename = os.path.expanduser(config["data"][name]) + assert os.path.exists(filename) + return yaml.safe_load(open(filename)) + + def check_conference_web_site(name: str, src_url: str, year: int) -> bool: """Check if an individual web site is live.""" assert "{year}" in src_url diff --git a/conference/__init__.py b/conference/__init__.py deleted file mode 100644 index 6891012..0000000 --- a/conference/__init__.py +++ /dev/null @@ -1,34 +0,0 @@ -"""Conference classes and functions.""" - -import configparser -import os -import typing -from datetime import date - -import yaml - -config_file_path = os.path.expanduser( - os.path.join( - os.getenv("XDG_CONFIG_HOME", "~/.config"), "conference-check", "config" - ) -) -assert os.path.exists(config_file_path) - -config = configparser.ConfigParser() -config.read(os.path.expanduser(config_file_path)) - - -class LiveConference(typing.TypedDict, total=False): - """Live conference.""" - - conference: str - year: int - live: date - url: str | None - - -def load_yaml(name: str) -> typing.Any: - """Load YAML.""" - filename = os.path.expanduser(config["data"][name]) - assert os.path.exists(filename) - return yaml.safe_load(open(filename)) diff --git a/templates/index.html b/templates/index.html deleted file mode 100644 index bcba09c..0000000 --- a/templates/index.html +++ /dev/null @@ -1,53 +0,0 @@ - - -
- -Date when website went live.
-| - {{ l.live.strftime("%a, %d %b %Y") }} - 🌍🎉 - | -- {{ l.conference }} {{ l.year }} - | - - {% endfor %} -