diff --git a/schedule.py b/schedule.py index 9a89588..c7173f5 100755 --- a/schedule.py +++ b/schedule.py @@ -6,13 +6,13 @@ import json import os import re import sys +import typing from datetime import date, datetime, timedelta -from typing import NoReturn -import ics +import ics # type: ignore import jinja2 import requests -from playwright.sync_api import Playwright, sync_playwright +from playwright.sync_api import Playwright, sync_playwright # type: ignore base_dir = os.path.dirname(__file__) @@ -24,8 +24,7 @@ template = env.get_template("schedule.html") config_location = os.path.join(base_dir, "config") auth_json_path = os.path.join(base_dir, "auth.json") -assert os.path.exists(config_location) -assert os.path.exists(auth_json_path) +assert os.path.exists(config_location) and os.path.exists(auth_json_path) config = configparser.ConfigParser() config.read(config_location) username = config["login"]["username"] @@ -88,8 +87,7 @@ def retrieve_schedule() -> requests.models.Response: def read_html_from_json(r: requests.models.Response) -> str: """Return HTML from the JSON response.""" - html: str = r.json()["html"] - return html + return typing.cast(str, r.json()["html"]) def login() -> None: @@ -98,7 +96,7 @@ def login() -> None: run(playwright) -def get_schedule_html() -> str | NoReturn: +def get_schedule_html() -> str | typing.NoReturn: """Grab the schedule and return the HTML part of the response.""" if not os.path.exists(auth_json_path): login() @@ -177,7 +175,7 @@ def html_to_ics(html: str) -> ics.Calendar: event = ics.Event() event.name = "Wheelie Fresh Bins" event.begin = d - event.end = d + timedelta(days=1) + event.make_all_day() cal.events.add(event) return cal @@ -196,7 +194,7 @@ def main() -> None: with open(ics_file, "w") as fh: fh.write(cal.serialize()) - now = datetime.utcnow() + now = datetime.utcnow() # need to rewrite this, utcnow is deprecated now_str = now.strftime("%Y-%m-%d_%H:%M") filename = os.path.join(data_dir, now_str + ".html") with open(filename, "w") as fh: