summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarkus Zapke-Grùˆndemann <info@keimlink.de>2012-01-03 18:30:22 +0100
committerMarkus Zapke-Grùˆndemann <info@keimlink.de>2012-01-03 18:30:22 +0100
commit9d873fd644b9cc265ad63dbc33f308dbd888ca19 (patch)
tree153f3a8448b4ca73eb72d8854afde240b9ac572d
parentc3acd7d9a445bfe84280fae750e04070278344d5 (diff)
Removed unused urllib2 import and improved example.
-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)