[gsoc-admin] EventConfig: Parse ics
- From: Lasse Schuirmann <lschuirma src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gsoc-admin] EventConfig: Parse ics
- Date: Wed, 12 Aug 2015 12:29:27 +0000 (UTC)
commit 07bf31a225aeeaf43c02ca491430efc5136da956
Author: Lasse Schuirmann <lasse schuirmann gmail com>
Date: Wed Aug 12 14:27:03 2015 +0200
EventConfig: Parse ics
data/config.cfg | 2 +-
email/config.py | 16 ++++++++++++++--
2 files changed, 15 insertions(+), 3 deletions(-)
---
diff --git a/data/config.cfg b/data/config.cfg
index cdb9984..db01259 100644
--- a/data/config.cfg
+++ b/data/config.cfg
@@ -9,7 +9,7 @@ path = data/{year}/students
[FINAL_EVALS]
type = date
ics_source = GSoC_Dates
-ics_description = .*[fF]inal evaluation deadline.*
+description_regex = .*[fF]inal evaluation deadline.*
[FOO]
type = mail_template
diff --git a/email/config.py b/email/config.py
index 20bbc2b..2703a79 100644
--- a/email/config.py
+++ b/email/config.py
@@ -4,6 +4,7 @@ import configparser
import datetime
import csv
from ics import Calendar
+import re
def apply_substitutions(uri):
@@ -37,7 +38,7 @@ class EventConfig:
def __init__(self):
self.ics_sources = {}
self.mail_templates = []
- self.dates = []
+ self.dates = {}
self.csvs = {}
def append_from_section(self, section):
@@ -55,7 +56,18 @@ class EventConfig:
return self.append_csv_from_section(section)
def append_date_from_section(self, section):
- raise NotImplementedError
+ events = self.ics_sources[section['ics_source']].events
+ regex = section['description_regex']
+ if not regex.endswith('$'):
+ regex += '$'
+ possible = list(filter(lambda ev:
+ re.match(regex, ev.description) is not None,
+ events))
+ assert len(possible) == 1, ("There are {num} possible events that "
+ "match the given regex '{regex}', only 1 "
+ "allowed.".format(num=len(possible),
+ regex=regex))
+ self.dates[section.name] = possible[0]
def append_mail_from_section(self, section):
raise NotImplementedError
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]