summaryrefslogtreecommitdiff
path: root/sublab_project
diff options
context:
space:
mode:
Diffstat (limited to 'sublab_project')
-rw-r--r--sublab_project/calendarium/calendarium.py10
1 files changed, 4 insertions, 6 deletions
diff --git a/sublab_project/calendarium/calendarium.py b/sublab_project/calendarium/calendarium.py
index 4ffcfe4..9935ace 100644
--- a/sublab_project/calendarium/calendarium.py
+++ b/sublab_project/calendarium/calendarium.py
@@ -1,7 +1,7 @@
-import urllib2
import icalendar
from dateutil.rrule import rrulestr
+
class Event(object):
def __init__(self, name, description, start, end):
self.name = name
@@ -14,12 +14,12 @@ class Event(object):
__name__, self.__class__.__name__,
repr(self.name), repr(self.start), repr(self.end))
+
class Calendarium(object):
def __init__(self, string):
"""
Loads a calendar from the string and provides a nice API to it.
"""
-
self.calendar = icalendar.Calendar.from_string(string)
def get_events(self, after, before):
@@ -67,10 +67,8 @@ if __name__ == '__main__':
from datetime import datetime
import urllib2
- calendar_request = urllib2.urlopen('https://sublab.org:5232/calendars/events')
- calendar = Calendarium(calendar_request.read())
- calendar_request.close()
-
+ response = urllib2.urlopen('https://sublab.org:5232/calendars/events')
+ calendar = Calendarium(response.read())
now = datetime.now()
events = list(calendar.get_events(now-relativedelta(days=1), now+relativedelta(months=+2)))
events.sort(key=lambda x:x.start)