Make events all day events

Closes: #1
This commit is contained in:
Edward Betts 2023-12-21 14:25:51 +00:00
parent 775826349b
commit 26c8ef7b14

View file

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