changeset 40:c4e8d697326b

wall calendar html generator
author drewp@bigasterisk.com
date Mon, 27 Nov 2023 12:04:28 -0800
parents 119f0cb719eb
children ab54c9f65f76
files pdm.lock pyproject.toml wall_calendar.css wall_calendar.py
diffstat 4 files changed, 80 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/pdm.lock	Sun Nov 12 23:31:03 2023 -0800
+++ b/pdm.lock	Mon Nov 27 12:04:28 2023 -0800
@@ -5,7 +5,7 @@
 groups = ["default"]
 strategy = ["cross_platform"]
 lock_version = "4.4"
-content_hash = "sha256:2c0fcd40b87683310b68afd0c1e74ab9bf1c42819da0cd19d7620da06b3399ae"
+content_hash = "sha256:2931324539323b9cce5b94de69a4f5cb4a7402d15fe7592945994fe49f7636f6"
 
 [[package]]
 name = "aiohttp"
@@ -437,6 +437,15 @@
 ]
 
 [[package]]
+name = "htmlgenerator"
+version = "1.2.28"
+summary = "Declarative HTML templating system with lazy rendering"
+files = [
+    {file = "htmlgenerator-1.2.28-py3-none-any.whl", hash = "sha256:3299b67da0d4bb7b4c640dd5dd7a41743d78cf3264c85564010444a691483d0b"},
+    {file = "htmlgenerator-1.2.28.tar.gz", hash = "sha256:e127d46311b9d28a6be6ce43417dc2a338b6c1a6f0aa5d2ba14319c7f5beb295"},
+]
+
+[[package]]
 name = "httplib2"
 version = "0.22.0"
 requires_python = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*"
--- a/pyproject.toml	Sun Nov 12 23:31:03 2023 -0800
+++ b/pyproject.toml	Mon Nov 27 12:04:28 2023 -0800
@@ -15,10 +15,10 @@
     "rdflib>=6.1.1",
     "starlette-exporter>=0.17.1",
     "starlette>=0.32.0post1",
-
     "patchablegraph>=1.5.0",
     "rdfdb==0.24.0",
     "background-loop>=1.8.0",
+    "htmlgenerator>=1.2.28",
 ]
 requires-python = ">=3.11"
 license = {text = "MIT"}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/wall_calendar.css	Mon Nov 27 12:04:28 2023 -0800
@@ -0,0 +1,29 @@
+@import url("https://fonts.googleapis.com/css2?family=Titillium+Web:wght@600&display=swap");
+body {
+  display: flex;
+  flex-direction: column;
+  height: 100vh;
+  margin: 0;
+  font-family: "Titillium Web", sans-serif;
+}
+body,
+table {
+  font-size: 20px;
+}
+table {
+  border-collapse: collapse;
+  width: 100%;
+  flex-grow: 1;
+}
+th,
+td {
+  border: 1px solid black;
+  vertical-align: top;
+  padding-left: 6px;
+}
+th {
+  width: 1%;
+}
+tr {
+  height: 10%;
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/wall_calendar.py	Mon Nov 27 12:04:28 2023 -0800
@@ -0,0 +1,40 @@
+import calendar
+import datetime
+import itertools
+import sys
+
+from htmlgenerator import BODY, H1, HEAD, HTML, SPAN, STYLE, TABLE, TBODY, TD, TH, TR, mark_safe, render
+
+c = calendar.TextCalendar(firstweekday=6)
+
+start = datetime.date.today()
+start = start - datetime.timedelta(days=start.weekday() + 1)
+offset = itertools.count()
+currentMonth = -1
+
+
+def nextDayLabel():
+    global currentMonth
+    thisDay = start + datetime.timedelta(days=next(offset))
+    month = ''
+    if thisDay.month != currentMonth:
+        month = f'{calendar.month_name[thisDay.month]} '
+        currentMonth = thisDay.month
+    return f'{month}{thisDay.day}'
+
+
+def weekdayLabels():
+    row = [TH(c.formatweekday(i, width=100)) for i in c.iterweekdays()]
+    return TR(*row)
+
+
+def nextWeekDays():
+    return TR(*[TD(SPAN(nextDayLabel(), class_="day")) for wd in c.iterweekdays()])
+
+
+sys.stdout.write(
+    render(
+        HTML(  #
+            HEAD(STYLE(mark_safe(open('wall_calendar.css').read()))),  #
+            BODY(H1("todo"), TABLE(*weekdayLabels(), TBODY(*[nextWeekDays() for week in range(8)])))),
+        {}))