Commit 27ee5a27 authored by erdnaxe's avatar erdnaxe 🎇

Initial commit

# IDE specific
# User specific
# Python specific
import re
from datetime import date
from icalendar_tools import get_event_start_date
def filter_date(event) -> bool:
"""Return true if event day is today or in the future"""
event_date = get_event_start_date(event)
if event_date:
return event_date >=
# If there is a bug in data then do not filter
return True
def filter_group(event, selected_groups) -> bool:
"""Filter group according to the group selected"""
summary = event.get('summary')
summary_search ='([0-9]{3}) - ([A-Z]{2}) \(grpe : ([^\)]*)\)', summary, re.IGNORECASE)
if summary_search:
ue, group =,
if int(ue) in selected_groups:
if group in selected_groups[int(ue)]:
# Group was selected
return True
# Group is not the one selected
print('-- UE', ue, 'group', group, 'removed')
return False
# If there is not a group specified do not filter
return True
from datetime import datetime, date
from typing import Union
from icalendar import Calendar
from requests import get
from requests.auth import HTTPBasicAuth
def download_icalendar(url: str, login: str, password: str) -> Calendar:
"""Download and parse an icalendar file with authentication"""
# Download calendar
print('Downloading', url)
request = get(url, auth=HTTPBasicAuth(login, password))
content = request.text
# Parse to create a calendar
return Calendar.from_ical(content)
def get_event_start_date(event) -> Union[date, bool]:
"""Return start date of an event"""
event_date = event.decoded('dtstart')
if isinstance(event_date, datetime):
elif isinstance(event_date, date):
return event_date
return False
from urllib.parse import urljoin
import keyring
import yaml
from filters import filter_date, filter_group
from icalendar_tools import download_icalendar, get_event_start_date
with open("config.yml", 'r') as f:
config = yaml.load(f)
base_url = config['base_url']
calendars_url = [urljoin(base_url, r) for r in config['calendars_url']]
login = config['login']
selected_groups = config['selected_groups']
password = keyring.get_password('sogo', login)
for url in calendars_url:
cal = download_icalendar(url, login, password)
for event in cal.walk():
# If it is an event in the future
if == 'VEVENT' and filter_date(event) and filter_group(event, selected_groups):
print(event.get('summary'), get_event_start_date(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