"""Build html to be served at agenda.blaise.zone.""" import os import pathlib import subprocess import datetime __here__ = pathlib.Path(__file__).parent # consume org file -------------------------------------------------------------------------------- global latest_scheduled latest_scheduled = datetime.date.today() class Event: def __init__(self, line): global latest_scheduled # timestamp (start time) year, month, day = (int(s) for s in line.split("<")[1][0:10].split("-")) self.timestamp = datetime.date(year, month, day) if self.timestamp > latest_scheduled: latest_scheduled = self.timestamp # end time if "--<" in line: year, month, day = (int(s) for s in line.split("--<")[1][0:10].split("-")) self.end = datetime.date(year, month, day) if self.end > latest_scheduled: latest_scheduled = self.end else: self.end = None # time of day tod = line[line.find("<") + 1 : line.find(">")][15:] # description self.description = " ".join(filter(None, [tod, line.split(">")[-1].strip()])) org_fp = "/home/nginx/org/agenda.org" events = [] with open(org_fp, "r") as org: for line in org: line = line.strip() if not line: continue if not line[0] == "*": continue if ":private:" in line: continue if ":info:" in line: continue events.append(Event(line)) url = "https://outlook.office365.com/owa/calendar/db2d3e0f0490459a80c4b837118e4bf1@wisc.edu/f6a2b5209cd6432c96f52939cacdbedd2266851683387467601/calendar.ics" subprocess.run(["curl", url, "-o", "/home/nginx/pycal2org/uw-madison.ics"]) subprocess.run(["python3", "/home/nginx/pycal2org/pycal2org.py", "/home/nginx/pycal2org/uw-madison.ics", ">", "/home/nginx/pycal2org/uw-madison.org"]) org_fp = "/home/nginx/pycal2org/uw-madison.org" with open(org_fp, "r") as org: for line in org: line = line.strip() if not line: continue if not line[0] == "*": continue if ":private:" in line: continue if ":info:" in line: continue events.append(Event(line)) # create html ------------------------------------------------------------------------------------- today = datetime.date.today() if not os.path.isdir(__here__ / "public"): os.mkdir(__here__ / "public") head = """
")
html.write("Welcome to my public agenda!
\n")
html.write("All timestamps are in 'blaise-local-time'.
\n")
html.write("Thanks for stopping by! —Blaise\n")
html.write("
") html.write(f"built {datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')} UTC") html.write("
") html.write("") html.write("\n") html.write("\n")