From 0936e1dfc4f0efe12576949c79daec246ded73ee Mon Sep 17 00:00:00 2001 From: Bezleputh Date: Fri, 11 Sep 2015 15:53:21 +0200 Subject: [PATCH] [calendar] add timezone parameter to calendarevent in order order do get the good date/hours in ical exports --- modules/agendadulibre/module.py | 15 ++++++++++++++- modules/allocine/browser.py | 1 + modules/hybride/calendar.py | 1 + modules/razibus/calendar.py | 1 + weboob/applications/boobcoming/boobcoming.py | 12 ++++++++++-- weboob/capabilities/calendar.py | 1 + 6 files changed, 28 insertions(+), 3 deletions(-) diff --git a/modules/agendadulibre/module.py b/modules/agendadulibre/module.py index 14c9e8ea..b0735c60 100644 --- a/modules/agendadulibre/module.py +++ b/modules/agendadulibre/module.py @@ -128,6 +128,19 @@ class AgendadulibreModule(Module, CapCalendarEvent): return self.browser.get_event(event_id) def fill_obj(self, event, fields): - return self.browser.get_event(event.id, event) + event = self.browser.get_event(event.id, event) + choice = self.config['region'].get().split('#') + selected_region = '' if len(choice) < 2 else choice[-1] + if selected_region == '23': + event.timezone = 'America/Guadeloupe' + elif selected_region == '24': + event.timezone = 'America/Guyana' + elif selected_region == '26': + event.timezone = 'Indian/Reunion' + elif selected_region == '25': + event.timezone = 'America/Martinique' + else: + event.timezone = 'Europe/Paris' + return event OBJECTS = {AgendadulibreBrowser: fill_obj} diff --git a/modules/allocine/browser.py b/modules/allocine/browser.py index f1344adc..378e16d6 100644 --- a/modules/allocine/browser.py +++ b/modules/allocine/browser.py @@ -645,4 +645,5 @@ class AllocineBrowser(Browser): event.location = location event.start_date = start_date event.summary = summary + event.timezone = 'Europe/Paris' yield event diff --git a/modules/hybride/calendar.py b/modules/hybride/calendar.py index e724ddd1..63c2ff14 100644 --- a/modules/hybride/calendar.py +++ b/modules/hybride/calendar.py @@ -30,3 +30,4 @@ class HybrideCalendarEvent(BaseCalendarEvent): self.transp = TRANSP.TRANSPARENT self.status = STATUS.CONFIRMED self.category = CATEGORIES.CINE + self.timezone = 'Europe/Paris' diff --git a/modules/razibus/calendar.py b/modules/razibus/calendar.py index fd839f3c..4cdc4fc2 100644 --- a/modules/razibus/calendar.py +++ b/modules/razibus/calendar.py @@ -28,3 +28,4 @@ class RazibusCalendarEvent(BaseCalendarEvent): self.transp = TRANSP.TRANSPARENT self.status = STATUS.CONFIRMED self.category = CATEGORIES.CONCERT + self.timezone = 'Europe/Paris' diff --git a/weboob/applications/boobcoming/boobcoming.py b/weboob/applications/boobcoming/boobcoming.py index fd21dbe5..49d89d25 100644 --- a/weboob/applications/boobcoming/boobcoming.py +++ b/weboob/applications/boobcoming/boobcoming.py @@ -20,6 +20,7 @@ from __future__ import print_function from datetime import time, datetime +from dateutil import tz from weboob.tools.date import parse_date from weboob.tools.application.formatters.iformatter import IFormatter, PrettyFormatter @@ -54,11 +55,18 @@ class ICalFormatter(IFormatter): def format_obj(self, obj, alias): result = u'BEGIN:VEVENT\r\n' + utc_zone = tz.gettz('UTC') + + event_timezone = tz.gettz(obj.timezone) start_date = obj.start_date if not empty(obj.start_date) else datetime.now() - result += u'DTSTART:%s\r\n' % start_date.strftime("%Y%m%dT%H%M%SZ") + start_date = start_date.replace(tzinfo=event_timezone) + utc_start_date = start_date.astimezone(utc_zone) + result += u'DTSTART:%s\r\n' % utc_start_date.strftime("%Y%m%dT%H%M%SZ") end_date = obj.end_date if not empty(obj.end_date) else datetime.combine(start_date, time.max) - result += u'DTEND:%s\r\n' % end_date.strftime("%Y%m%dT%H%M%SZ") + end_date = end_date.replace(tzinfo=event_timezone) + utc_end_date = end_date.astimezone(utc_zone) + result += u'DTEND:%s\r\n' % utc_end_date.strftime("%Y%m%dT%H%M%SZ") result += u'SUMMARY:%s\r\n' % obj.summary result += u'UID:%s\r\n' % obj.id diff --git a/weboob/capabilities/calendar.py b/weboob/capabilities/calendar.py index c37c19fb..f7c5c639 100644 --- a/weboob/capabilities/calendar.py +++ b/weboob/capabilities/calendar.py @@ -44,6 +44,7 @@ class BaseCalendarEvent(BaseObject): url = StringField('URL of the event') start_date = DateField('Start date of the event') end_date = DateField('End date of the event') + timezone = StringField('Timezone of the event in order to convert to utc time', default='Etc/UCT') summary = StringField('Title of the event') city = StringField('Name of the city in witch event will take place') location = StringField('Location of the event')