From 17fba39d4beeecdeb4c84565e9b3d0c2054d5dca Mon Sep 17 00:00:00 2001 From: Blaise Thompson Date: Mon, 5 Jul 2021 22:40:33 -0500 Subject: build no html --- build.py | 119 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ build.sh | 2 - build_html.py | 119 ---------------------------------------------------------- 3 files changed, 119 insertions(+), 121 deletions(-) create mode 100644 build.py delete mode 100755 build.sh delete mode 100644 build_html.py diff --git a/build.py b/build.py new file mode 100644 index 0000000..f4ee289 --- /dev/null +++ b/build.py @@ -0,0 +1,119 @@ +"""Build html to be served at agenda.blaise.zone.""" + +import os +import pathlib + +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)) + + +# create html ------------------------------------------------------------------------------------- + + +today = datetime.date.today() + +if not os.path.isdir(__here__ / "public"): + os.mkdir(__here__ / "public") + +head = """ + + + agenda.blaise.zone + + +""" + +with open(__here__ / "public" / "index.html", "w") as html: + # header + html.write("\n") + html.write(head) + html.write("\n") + html.write("

blaise-agenda

\n") + html.write("
") + html.write("

") + 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("

") + # body + monday = today - datetime.timedelta(days=today.weekday()) + while True: + year, week, day = monday.isocalendar() + id = f"{year}-w{week}" + html.write( + f'

{year} W{week}

' + ) + for i in range(7): + day = monday + datetime.timedelta(days=i) + id = day.isoformat() + html.write( + f"

{day.isoformat()} {day.strftime('%A')}

" + ) + for event in events: + if event.end: + if event.timestamp <= day and event.end >= day: + total = event.end - event.timestamp + elapsed = total - (event.end - day) + html.write( + f"(day {elapsed.days+1}/{total.days+1}) {event.description}
" + ) + else: + if event.timestamp == day: + html.write(f"{event.description}
") + # increment + monday += datetime.timedelta(days=7) + if monday > latest_scheduled: + break + # footer + html.write("
") + html.write(f"last updated {today.isoformat()}") + html.write("\n") + html.write("\n") diff --git a/build.sh b/build.sh deleted file mode 100755 index 7c74c36..0000000 --- a/build.sh +++ /dev/null @@ -1,2 +0,0 @@ -python3 /home/blaise/source/agenda/build_html.py -/home/blaise/source/agenda/publicize.sh diff --git a/build_html.py b/build_html.py deleted file mode 100644 index d05f8cf..0000000 --- a/build_html.py +++ /dev/null @@ -1,119 +0,0 @@ -"""Build html to be served at agenda.blaise.zone.""" - -import os -import pathlib - -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/blaise/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)) - - -# create html ------------------------------------------------------------------------------------- - - -today = datetime.date.today() - -if not os.path.isdir(__here__ / "public"): - os.mkdir(__here__ / "public") - -head = """ - - - agenda.blaise.zone - - -""" - -with open(__here__ / "public" / "index.html", "w") as html: - # header - html.write("\n") - html.write(head) - html.write("\n") - html.write("

blaise-agenda

\n") - html.write("
") - html.write("

") - 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("

") - # body - monday = today - datetime.timedelta(days=today.weekday()) - while True: - year, week, day = monday.isocalendar() - id = f"{year}-w{week}" - html.write( - f'

{year} W{week}

' - ) - for i in range(7): - day = monday + datetime.timedelta(days=i) - id = day.isoformat() - html.write( - f"

{day.isoformat()} {day.strftime('%A')}

" - ) - for event in events: - if event.end: - if event.timestamp <= day and event.end >= day: - total = event.end - event.timestamp - elapsed = total - (event.end - day) - html.write( - f"(day {elapsed.days+1}/{total.days+1}) {event.description}
" - ) - else: - if event.timestamp == day: - html.write(f"{event.description}
") - # increment - monday += datetime.timedelta(days=7) - if monday > latest_scheduled: - break - # footer - html.write("
") - html.write(f"last updated {today.isoformat()}") - html.write("\n") - html.write("\n") -- cgit v1.2.3