Commit 1d4765c6 authored by Matthieu Boileau's avatar Matthieu Boileau
Browse files

Merge branch 'dev-calendar' into 'master'

ical: added colloquium to merged events

See merge request !14
parents 243e134f 4bcd8835
Pipeline #19457 passed with stages
in 17 seconds
__version__ = '0.3.9'
__version__ = '0.3.10'
......@@ -57,7 +57,8 @@ def build_calendar(prodid: str, ical_events: list) -> str:
return cal.to_ical().decode('UTF-8')
def merge_calendars(prodid: str, sem_calendar_paths: list) -> str:
def merge_calendars(prodid: str, sem_calendar_paths: list,
event_types: set) -> str:
"""
Read a list of seminars iCalendar files and merge them into
a single iCalendar file
......@@ -69,8 +70,9 @@ def merge_calendars(prodid: str, sem_calendar_paths: list) -> str:
for calendar_path in sorted(sem_calendar_paths):
with open(calendar_path) as f:
sem_cal = Calendar.from_ical(f.read())
m = re.match(r"-\/\/.*\/\/Séminaire (.*)\/\/.*$", sem_cal['prodid'])
# Merge only seminars
# Merge only seminars and Colloquium
pattern = r"^-\/\/.*\/\/((" + "|".join(event_types) + r") .*)\/\/.*$"
m = re.match(pattern, sem_cal['prodid'])
if m:
summary_prefix = m.group(1)
for event in sem_cal.walk(name='VEVENT'):
......
......@@ -824,7 +824,8 @@ class SeminarTopIndexPage(Page):
-//{self.conf.site['calendar']['organization']}//séminaires//FR")
ics_file_paths = Path(self.conf.output_path / 'cal').glob('**/*.ics')
ical_content = merge_calendars(prodid, ics_file_paths)
ical_content = merge_calendars(prodid, ics_file_paths,
{'Séminaire', 'Colloquium'})
self.ical_url = write_calendar_file('séminaires.ics',
self.conf,
ical_content)
......
from re import I
from faker import Faker
from pathlib import Path
import filecmp
......@@ -139,13 +140,14 @@ def test_merge_calendars(tmpdir):
ics_file_paths = Path(tmpdir).glob('**/*.ics')
prodid = f'-//Pilab//Séminaires//FR'
ical_merged = calendar.merge_calendars(prodid, ics_file_paths)
ical_merged = calendar.merge_calendars(prodid, ics_file_paths,
{'Séminaire', 'Colloquium'})
assert ical_merged.startswith("""\
BEGIN:VCALENDAR
VERSION:2.0
PRODID:-//Pilab//Séminaires//FR
BEGIN:VEVENT
SUMMARY:Antoine-Lucas Andre - Trois passer calme pleurer.
SUMMARY:Séminaire Antoine-Lucas Andre - Trois passer calme pleurer.
DTSTART;VALUE=DATE-TIME:19870422T043021
DTEND;VALUE=DATE-TIME:19870422T043021
DTSTAMP;VALUE=DATE-TIME:19970924T214947Z
......@@ -185,8 +187,8 @@ BEGIN:VCALENDAR
VERSION:2.0
PRODID:-//Pilab//séminaires//FR
BEGIN:VEVENT
SUMMARY:Beau souffrance réveiller beauté horizon manquer - Lucie Daniel
- Admettre propre existence crainte mot prochain bas
SUMMARY:Séminaire Beau souffrance réveiller beauté horizon manquer - Lu
cie Daniel - Admettre propre existence crainte mot prochain bas
DTSTART;VALUE=DATE-TIME:20180625T042207
DTEND;VALUE=DATE-TIME:20180625T052207
""")
......
Supports Markdown
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