summaryrefslogtreecommitdiff
path: root/generate-schedule.py
diff options
context:
space:
mode:
Diffstat (limited to 'generate-schedule.py')
-rwxr-xr-xgenerate-schedule.py155
1 files changed, 155 insertions, 0 deletions
diff --git a/generate-schedule.py b/generate-schedule.py
new file mode 100755
index 0000000..1541ca6
--- /dev/null
+++ b/generate-schedule.py
@@ -0,0 +1,155 @@
+#!/usr/bin/env python3
+
+from datetime import date
+from dataclasses import dataclass
+import calendar
+
+@dataclass
+class Location:
+ name: str
+ url: str
+ neighborhood: str
+ time: str = None
+ info: str = None
+
+@dataclass
+class Event:
+ location: Location
+ when: date
+ time: str = None
+ info: str = None
+ special: bool = False
+ cancelled: bool = False
+
+def render_schedule(events):
+ s = ''
+ week = None
+ for event in events:
+ weekday = calendar.day_name[event.when.weekday()]
+ month = calendar.month_name[event.when.month]
+ day = event.when.day
+ time = event.time or event.location.time
+ assert time, 'no time given either in location or event'
+ info = event.info or event.location.info
+ infotxt = f'<br><div class="info">{info}</div>' if info else ''
+
+ week_change = False
+ new_week = event.when.isocalendar()[1]
+ if week is not None and week != new_week:
+ week_change = True
+ week = new_week
+
+ if week_change:
+ s += '<br>\n'
+ s += f'''<div class="event {'special' if event.special else ''} {'cancelled' if event.cancelled else ''}">
+ <div class="event-data">
+ <strong>{weekday}, {month} {day}</strong> &middot; {time}
+ </div>
+ <div class="instance">
+ <a href="{event.location.url}">{event.location.name}</a>,
+ <span class="neighborhood">{event.location.neighborhood}</span>
+ {infotxt}
+ </div>
+</div>'''
+
+ return s
+
+mccarren = Location(
+ "Spritzenhaus33",
+ "https://maps.app.goo.gl/4jKTTTJ3h61dGPyz6",
+ "Williamsburg",
+ "6:30p",
+)
+
+jefferson = Location(
+ "Jefferson Market Library",
+ "https://maps.app.goo.gl/UTNUqUdEjYCssiMx5",
+ "Greenwich Village",
+ "6p",
+ info="1<sup>st</sup> floor Willa Cather Room; take a left at entrance, straight through children&rsquo;s room"
+)
+
+nook = Location(
+ "Nook",
+ "https://maps.app.goo.gl/X2fYE3EpeHhQhgYD8",
+ "Bushwick",
+ "9a",
+)
+
+liz = Location(
+ "Liz&rsquo;s Book Bar",
+ "https://maps.app.goo.gl/6hgstJRcd2TKa96x5",
+ "Carroll Gardens",
+ "7p",
+)
+
+abraco = Location(
+ "Abraço",
+ "https://maps.app.goo.gl/6w6GzymLNy9vdgqG9",
+ "East Village",
+ "6p",
+)
+
+bookclub = Location(
+ "Book Club Bar",
+ "https://maps.app.goo.gl/ewGbWuEjp7cedMrb7",
+ "East Village",
+ "9p",
+)
+
+dekalblibrary = Location(
+ "Dekalb Library",
+ "https://maps.app.goo.gl/G3D2hQ6og5DkBQH86",
+ "Bushwick",
+)
+
+wyckoffbondgarden = Location(
+ "Wyckoff-Bond Community Garden",
+ "https://maps.app.goo.gl/qWKXJhrvvpvLeFLy7",
+ "Boerum Hill",
+ info="Hosted by Carroll Gardens Library"
+)
+
+bkcentrallibrary = Location(
+ "Brooklyn Central Library",
+ "https://maps.app.goo.gl/fPijDbTN47TbFpFf6",
+ "Prospect Heights",
+ info="Trustees Room"
+)
+
+bushwicklibrary = Location(
+ "Bushwick Library",
+ "https://maps.app.goo.gl/2mnX1sDSrBv1jKQ3A",
+ "Bushwick",
+)
+
+schedule = [
+ Event(jefferson, date(2024, 10, 30)),
+ Event(nook, date(2024, 11, 2)),
+ Event(bookclub, date(2024, 11, 3)),
+ Event(mccarren, date(2024, 11, 4), info='Book Swap and <a href="https://booksthroughbarsnyc.org/donate/donate-books/">NYC Books Through Bars</a> Book Drive.', special=True),
+ Event(jefferson, date(2024, 11, 6), info='Elevator in lobby to third floor. Book Swap and <a href="https://booksthroughbarsnyc.org/donate/donate-books/">NYC Books Through Bars</a> Book Drive.', special=True),
+ Event(nook, date(2024, 11, 9)),
+ Event(mccarren, date(2024, 11, 11)),
+ Event(abraco, date(2024, 11, 13), special=True, info='Wednesday Jefferson Market Library Quiet Reading moved for this week.'),
+ Event(bushwicklibrary, date(2024, 11, 14), time='6p', special=True),
+ Event(nook, date(2024, 11, 16)),
+ Event(wyckoffbondgarden, date(2024, 11, 16), time='12p', special=True),
+ Event(mccarren, date(2024, 11, 18)),
+ Event(jefferson, date(2024, 11, 20)),
+ Event(bkcentrallibrary, date(2024, 11, 20), time='6:30p', special=True),
+ Event(dekalblibrary, date(2024, 11, 21), time='6p', special=True),
+ Event(nook, date(2024, 11, 23)),
+ Event(mccarren, date(2024, 11, 25)),
+ Event(jefferson, date(2024, 11, 27), info='<strong>Cancelled due to Thanksgiving.</strong>', cancelled=True),
+ Event(nook, date(2024, 11, 30)),
+ # Event(bookclub, date(2024, 12, 1)),
+ # Event(liz, date(2024, 12, 3)),
+] # maybe autosort it and sort code by event?
+
+with open('index.base') as base:
+ txt = base.read()
+ html = render_schedule(schedule)
+ txt = txt.replace('{SCHEDULE}', html)
+ with open('index.html', 'w') as index:
+ index.write(txt)