summaryrefslogtreecommitdiff
path: root/generate-schedule.py
blob: c7ba46a4845a1a9fcac3989d1293fe1217213895 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
#!/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'<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 ''} {'changed' if event.changed 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), 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='<strong>Cancelled due to Thanksgiving.</strong>', cancelled=True),
    Event(nook, date(2024, 11, 30)),
    Event(bookclub, date(2024, 12, 1)),
    Event(mccarren, date(2024, 12, 2)),
    Event(liz, date(2024, 12, 3)),
    Event(jefferson, date(2024, 12, 4)),
    Event(nook, date(2024, 12, 7)),
    Event(mccarren, date(2024, 12, 9)),
    Event(jefferson, date(2024, 12, 11)),
    Event(nook, date(2024, 12, 14)),
    Event(mccarren, date(2024, 12, 16)),
    Event(jefferson, date(2024, 12, 18)),
    Event(nook, date(2024, 12, 21)),
] # 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)