-
Notifications
You must be signed in to change notification settings - Fork 2
/
freeze.py
33 lines (23 loc) · 881 Bytes
/
freeze.py
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
from flask_frozen import Freezer
from app import app
from app.models import EventAttendeeJunction, Event
from datetime import datetime, timedelta
import pytz
freezer = Freezer(app)
@freezer.register_generator
def event():
for event in Event.query.all():
yield {"event_public_id": event.public_id}
@freezer.register_generator
def attendee_rsvp():
utc = pytz.UTC
now = utc.localize(datetime.now())
time_diff = timedelta(days=1)
for event in Event.query.all():
if event.date >= now - time_diff:
print(f"Generating rsvps for {event.event} on {event.date}")
for rsvp in EventAttendeeJunction.query.filter_by(event_id=event.id).all():
print(f"Making rsvp for {rsvp.attendee.attendee}")
yield {"event_junction_public_id": rsvp.public_id}
if __name__ == "__main__":
freezer.freeze()