Commit e0809689 authored by erdnaxe's avatar erdnaxe 🎇

Add events from last week

parent f5c61506
import logging import logging
import re import re
from datetime import date from datetime import date, timedelta
from icalendar_tools import get_event_start_date from icalendar_tools import get_event_start_date
...@@ -8,11 +8,12 @@ logger = logging.getLogger('Filters') ...@@ -8,11 +8,12 @@ logger = logging.getLogger('Filters')
def filter_date(event) -> bool: def filter_date(event) -> bool:
"""Return true if event day is today or in the future""" """Return true if event day is after the beginning of last week"""
event_date = get_event_start_date(event) event_date = get_event_start_date(event)
if event_date: if event_date:
return event_date >= date.today() from_date = date.today() - timedelta(weeks=1)
return event_date >= from_date
else: else:
# If there is a bug in data then do not filter # If there is a bug in data then do not filter
summary = event.get('summary') summary = event.get('summary')
......
...@@ -26,7 +26,7 @@ for url in config.calendars_url: ...@@ -26,7 +26,7 @@ for url in config.calendars_url:
# Copy events # Copy events
for event in online_calendar.get_events(): for event in online_calendar.get_events():
# If it is an event in the future and in the correct group # If it is an event more recent than past week and in the correct group
if filter_date(event) and filter_group(event, config.selected_groups): if filter_date(event) and filter_group(event, config.selected_groups):
logging.debug('An event was added : {}'.format(event.get('summary'))) logging.debug('An event was added : {}'.format(event.get('summary')))
calendar.add_component(event) calendar.add_component(event)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment