event "id" includes begin time

This commit is contained in:
Tomáš Mládek 2021-02-27 10:53:27 +01:00
parent f78d5e414d
commit 08fd240054

14
bot.py
View file

@ -8,7 +8,7 @@ from asyncio import sleep
import aiohttp import aiohttp
import arrow import arrow
from ics import Calendar from ics import Calendar, Event
from config import Config from config import Config
@ -74,6 +74,10 @@ async def send_message(text):
logging.debug(f"RECV: [{result.status}] {await result.text()}") logging.debug(f"RECV: [{result.status}] {await result.text()}")
def get_event_id(event: Event) -> str:
return f"{event.begin}//{event.name}"
async def main(): async def main():
try: try:
with open(STATE_PATH, 'rb') as state_fp: with open(STATE_PATH, 'rb') as state_fp:
@ -93,15 +97,15 @@ async def main():
logging.debug(f"Got {len(future_events)} future events...") logging.debug(f"Got {len(future_events)} future events...")
for event in future_events: for event in future_events:
if event.name not in state.notified and event.begin.shift(days=-2) < arrow.now(): if get_event_id(event) not in state.notified and event.begin.shift(days=-2) < arrow.now():
logging.info(f"Sending description of {event.name}") logging.info(f"Sending description of {event.name}")
await send_message(process_event(event, config.EVENT_TEMPLATE)) await send_message(process_event(event, config.EVENT_TEMPLATE))
state.notified.append(event.name) state.notified.append(get_event_id(event))
if event.name not in state.notified_soon and event.begin.shift(hours=-2) < arrow.now(): if get_event_id(event) not in state.notified_soon and event.begin.shift(hours=-2) < arrow.now():
logging.info(f"Notifying of {event.name}") logging.info(f"Notifying of {event.name}")
await send_message(process_event(event, config.SOON_TEMPLATE)) await send_message(process_event(event, config.SOON_TEMPLATE))
state.notified_soon.append(event.name) state.notified_soon.append(get_event_id(event))
with open(STATE_PATH, 'wb') as state_fp: with open(STATE_PATH, 'wb') as state_fp:
pickle.dump(state, state_fp) pickle.dump(state, state_fp)