summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBlaise Thompson <blaise@untzag.com>2019-06-22 16:25:49 -0500
committerBlaise Thompson <blaise@untzag.com>2019-06-22 16:25:49 -0500
commit26bbd1c75e83d0642f93c07cb8486525d40da0b1 (patch)
tree65705776395f8e805053c2ed7f6e15e9d631f52f
initial commit
-rw-r--r--.gitignore1
-rw-r--r--build_html.py112
-rw-r--r--public/style.css16
3 files changed, 129 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..6025ad7
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1 @@
+public/index.html
diff --git a/build_html.py b/build_html.py
new file mode 100644
index 0000000..7622c9a
--- /dev/null
+++ b/build_html.py
@@ -0,0 +1,112 @@
+"""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[0] == "*":
+ continue
+ if ":private:" 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>
+<head>
+ <meta charset="utf-8">
+ <title>agenda.blaise.zone</title>
+ <link rel="stylesheet" href="style.css">
+</head>
+"""
+
+with open(__here__ / "public" / "index.html", "w") as html:
+ # header
+ html.write("<!DOCTYPE html>\n")
+ html.write(head)
+ html.write("<body>\n")
+ html.write("<h1>agenda.blaise.zone</h1>\n")
+ html.write("Welcome to my public agenda!<br>\n")
+ html.write("All timestamps are in 'blaise-local-time'.<br>\n")
+ html.write("Thanks for stopping by! —Blaise\n")
+ # body
+ monday = today - datetime.timedelta(days=today.weekday())
+ while True:
+ html.write("<hr>")
+ year, week, day = monday.isocalendar()
+ id = f"{year}-w{week}"
+ html.write(
+ f'<h2 id="{id}"><a href=#{id} style=color:#f0c674>{year} W{week}</a></h2>'
+ )
+ for i in range(7):
+ day = monday + datetime.timedelta(days=i)
+ id = day.isoformat()
+ html.write(
+ f"<h3 id={id}><a href=#{id}>{day.isoformat()} {day.strftime('%A')}</a></h3>"
+ )
+ for event in events:
+ if event.end:
+ if event.timestamp <= day and event.end >= day:
+ total = event.end - event.timestamp
+ elapsed = day - event.end
+ html.write(
+ f"(day {elapsed.days+3}/{total.days+1}) {event.description}<br>"
+ )
+ else:
+ if event.timestamp == day:
+ html.write(f"{event.description}<br>")
+ # increment
+ monday += datetime.timedelta(days=7)
+ if monday > latest_scheduled:
+ break
+ # footer
+ html.write("<hr>")
+ html.write("</body>\n")
+ html.write("</html>\n")
diff --git a/public/style.css b/public/style.css
new file mode 100644
index 0000000..8a1a7d6
--- /dev/null
+++ b/public/style.css
@@ -0,0 +1,16 @@
+a {
+ text-decoration: none;
+ color: #81a2be;
+}
+
+body {
+ font-family: sans-serif;
+ margin: 40px auto;
+ max-width: 650px;
+ line-height: 1.6;
+ font-size: 16px;
+ background-color: #1d1f21;
+ color: #c5c8c6;
+ padding: 0 10px;
+ text-align: left;
+}