Skip to content

Commit 62a906d

Browse files
Niloth-ptimabbott
authored andcommitted
google-calendar: Send each reminder as its own message.
Currently, all the reminders are collected together before sending a message, and are formatted as bullet points in the same message. This commit uses a message per event, in preparation of adding more details to each reminder message.
1 parent 3db00f9 commit 62a906d

File tree

1 file changed

+19
-29
lines changed

1 file changed

+19
-29
lines changed

zulip/integrations/google/google-calendar

Lines changed: 19 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -233,34 +233,7 @@ def populate_events() -> Optional[None]:
233233
events.append((event["id"], start, "(No Title)"))
234234

235235

236-
def send_reminders() -> Optional[None]:
237-
messages = []
238-
keys = set()
239-
now = datetime.datetime.now(tz=pytz.utc)
240-
241-
for id, start, summary in events:
242-
dt = start - now
243-
if dt.days == 0 and dt.seconds < 60 * calendar_options.interval:
244-
# The unique key includes the start time, because of
245-
# repeating events.
246-
key = (id, start)
247-
if key not in sent:
248-
if start.hour == 0 and start.minute == 0:
249-
line = f"{summary} is today."
250-
else:
251-
line = "{} starts at {}".format(summary, start.strftime("%H:%M"))
252-
logging.info("Sending reminder: %s", line)
253-
messages.append(line)
254-
keys.add(key)
255-
256-
if not messages:
257-
return
258-
259-
if len(messages) == 1:
260-
message = "Reminder: " + messages[0]
261-
else:
262-
message = "Reminder:\n\n" + "\n".join("* " + m for m in messages)
263-
236+
def send_reminder_message(message: str, key: Tuple[str, datetime.datetime]) -> None:
264237
user_profile = zulip_client.get_profile()
265238
if calendar_options.channel is not None:
266239
result = zulip_client.send_message(
@@ -281,7 +254,24 @@ def send_reminders() -> Optional[None]:
281254
)
282255
if result["result"] != "success":
283256
logging.error("Error sending zulip message: %s: %s", result.get("code"), result.get("msg"))
284-
sent.update(keys)
257+
sent.add(key)
258+
259+
260+
def send_reminders() -> Optional[None]:
261+
now = datetime.datetime.now(tz=pytz.utc)
262+
263+
for id, start, summary in events:
264+
dt = start - now
265+
if dt.days == 0 and dt.seconds < 60 * calendar_options.interval:
266+
# The unique key includes the start time due to repeating events.
267+
key = (id, start)
268+
if key not in sent:
269+
if start.hour == 0 and start.minute == 0:
270+
message = f"{summary} is today."
271+
else:
272+
message = "{} starts at {}".format(summary, start.strftime("%H:%M"))
273+
logging.info("Sending reminder: %s", message)
274+
send_reminder_message(message, key)
285275

286276

287277
# Loop forever

0 commit comments

Comments
 (0)