#!/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 changed: 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'
{info}
' 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 += '
\n' s += f'''
{weekday}, {month} {day} · {time}
{event.location.name}, {event.location.neighborhood} {infotxt}
''' 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="1st floor Willa Cather Room; take a left at entrance, straight through children’s room" ) nook = Location( "Nook", "https://maps.app.goo.gl/X2fYE3EpeHhQhgYD8", "Bushwick", "9a", ) liz = Location( "Liz’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 NYC Books Through Bars Book Drive.', special=True), # Event(jefferson, date(2024, 11, 6), info='Elevator in lobby to third floor. Book Swap and NYC Books Through Bars Book Drive.', special=True), # Event(nook, date(2024, 11, 9)), # Event(mccarren, date(2024, 11, 11)), Event(abraco, date(2024, 11, 13), changed=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='Cancelled due to Thanksgiving.', 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)