#!/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 summermccarren = Location( "McCarren Park", "https://maps.app.goo.gl/7YQBG3XVHNLWkyAM9", "Williamsburg", "6:30p", info='North corner, west side. Rain or above 90°: at Spritzenhaus33.' ) 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="Willa Cather Room; left at door, 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" ) bkcentral_info_commons = Location( "Brooklyn Central Library", "https://maps.app.goo.gl/fPijDbTN47TbFpFf6", "Prospect Heights", info="Info Commons Lab" ) bushwicklibrary = Location( "Bushwick Library", "https://maps.app.goo.gl/2mnX1sDSrBv1jKQ3A", "Bushwick", ) sunsetpark = Location( "Sunset Park Library", "https://maps.app.goo.gl/ck5NMcK7nC189KCZ6", "Sunset Park", ) canarsielibrary = Location( "Canarsie Library", "https://maps.app.goo.gl/G7ek4jPEWDVSMevB9", "Canarsie", ) kingsbay = Location( "Kings Bay Library", "https://maps.app.goo.gl/1KKf7SqMbwXirKe29", "Kings Bay", ) easternparkway = Location( "Eastern Parkway Library", "https://maps.app.goo.gl/D5STnQQNC3XxKSiV8", "Crown Heights", ) windsorterrace = Location( "Windsor Terrace Library", "https://maps.app.goo.gl/My7eCEy91dF6mWSY7", "Windsor Terrace", ) greenpoint = Location( "Greenpoint Library", "https://maps.app.goo.gl/8y4hGLWHkKHd7KWRA", "Greenpoint", ) williamsburgh = Location( "Williamsburgh Library", "https://maps.app.goo.gl/hdy88ytUfUKpH9WY6", "Williamsburg", ) ridgewoodlibrary = Location( "Ridgewood Library", "https://maps.app.goo.gl/mE51fsx1HrSqFCvb9", "Ridgewood", ) artsculture = Location( "Library for Arts & Culture", "https://maps.app.goo.gl/GssCUr9QF2aFxgiQA", "Fort Greene", ) schedule = [ Event(nook, date(2025, 5, 17)), Event(summermccarren, date(2025, 5, 19)), Event(jefferson, date(2025, 5, 21)), Event(nook, date(2025, 5, 24)), Event(summermccarren, date(2025, 5, 26)), Event(jefferson, date(2025, 5, 28)), Event(nook, date(2025, 5, 31)), Event(summermccarren, date(2025, 6, 2)), Event(jefferson, date(2025, 6, 4)), Event(nook, date(2025, 6, 7)), Event(summermccarren, date(2025, 6, 9)), Event(windsorterrace, date(2025, 6, 10), time='6p'), Event(jefferson, date(2025, 6, 11)), Event(greenpoint, date(2025, 6, 12), time='6p'), Event(dekalblibrary, date(2025, 6, 12), time='6p'), Event(ridgewoodlibrary, date(2025, 6, 12), time='6p', info='Library garden. Inclement weather: in auditorium.'), Event(nook, date(2025, 6, 14)), Event(summermccarren, date(2025, 6, 16)), Event(jefferson, date(2025, 6, 18)), Event(nook, date(2025, 6, 21)), Event(summermccarren, date(2025, 6, 23)), Event(jefferson, date(2025, 6, 25)), Event(nook, date(2025, 6, 28)), Event(summermccarren, date(2025, 6, 30)), ] # 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)