event "id" includes begin time
This commit is contained in:
parent
f78d5e414d
commit
08fd240054
1 changed files with 9 additions and 5 deletions
14
bot.py
14
bot.py
|
@ -8,7 +8,7 @@ from asyncio import sleep
|
|||
|
||||
import aiohttp
|
||||
import arrow
|
||||
from ics import Calendar
|
||||
from ics import Calendar, Event
|
||||
|
||||
from config import Config
|
||||
|
||||
|
@ -74,6 +74,10 @@ async def send_message(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():
|
||||
try:
|
||||
with open(STATE_PATH, 'rb') as state_fp:
|
||||
|
@ -93,15 +97,15 @@ async def main():
|
|||
logging.debug(f"Got {len(future_events)} 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}")
|
||||
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}")
|
||||
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:
|
||||
pickle.dump(state, state_fp)
|
||||
|
|
Loading…
Reference in a new issue