From 9d873fd644b9cc265ad63dbc33f308dbd888ca19 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Markus=20Zapke-Gru=CC=88ndemann?= Date: Tue, 3 Jan 2012 18:30:22 +0100 Subject: Removed unused urllib2 import and improved example. --- sublab_project/calendarium/calendarium.py | 10 ++++------ 1 file 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) -- cgit v1.2.1