Skip to content

Commit

Permalink
Add dummy event for sync frequency
Browse files Browse the repository at this point in the history
  • Loading branch information
oliver-ni committed Oct 5, 2023
1 parent 1a1988f commit eaf79b1
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions hknweb/events/models/ical_view.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import random
import uuid
from datetime import datetime, timedelta

import icalendar
from django.conf import settings
from django.db import models
from django.urls import reverse

from hknweb.events.models import Event
from hknweb.events.utils import get_events


Expand All @@ -31,4 +34,30 @@ def to_ical_obj(self):
for event in events:
cal.add_component(event.to_ical_obj())

cal.add_component(self.dummy_event())
return cal

def dummy_event(self):
# Google Calendar doesn't let you configure how often to sync iCal feeds
# like Apple's Calendar app does. They say this can take up to 24 hours.

# According to https://webapps.stackexchange.com/a/66686, they probably
# look at how often the iCal feed itself changes and syncs more or less
# frequently based on that.

# So we add a dummy event in the far future that's randomized every time
# the feed is requested in hopes of making Google Calendar sync faster.

dt = datetime(3000, 1, 1) + timedelta(days=random.randrange(365))

event = icalendar.Event()
event.add("uid", "dummy")
event.add("summary", "Dummy Event")
event.add(
"description",
"Randomized dummy event to make Google Calendar sync faster",
)
event.add("dtstart", dt)
event.add("dtend", dt)
event.add("dtstamp", dt)
return event

0 comments on commit eaf79b1

Please sign in to comment.