def test_cal_Component_from_ical(self):
        # RecurrenceIDs may contain a TZID parameter, if so, they should create
        # a tz localized datetime, otherwise, create a naive datetime
        Component = icalendar.cal.Component
        componentStr = 'BEGIN:VEVENT\nRECURRENCE-ID;TZID=America/Denver:'\
                       + '20120404T073000\nEND:VEVENT'
        component = Component.from_ical(componentStr)
        self.assertEqual(
            str(component['RECURRENCE-ID'].dt.tzinfo.zone), "America/Denver")

        componentStr = 'BEGIN:VEVENT\nRECURRENCE-ID:20120404T073000\n'\
                       + 'END:VEVENT'
        component = Component.from_ical(componentStr)
        self.assertEqual(component['RECURRENCE-ID'].dt.tzinfo, None)
Esempio n. 2
0
    def test_cal_Component_from_ical(self):
        # RecurrenceIDs may contain a TZID parameter, if so, they should create
        # a tz localized datetime, otherwise, create a naive datetime
        Component = icalendar.cal.Component
        componentStr = 'BEGIN:VEVENT\nRECURRENCE-ID;TZID=America/Denver:'\
                       + '20120404T073000\nEND:VEVENT'
        component = Component.from_ical(componentStr)
        self.assertEqual(str(component['RECURRENCE-ID'].dt.tzinfo.zone),
                         "America/Denver")

        componentStr = 'BEGIN:VEVENT\nRECURRENCE-ID:20120404T073000\n'\
                       + 'END:VEVENT'
        component = Component.from_ical(componentStr)
        self.assertEqual(component['RECURRENCE-ID'].dt.tzinfo, None)
Esempio n. 3
0
    def make_ical(self, csv_configs=None):
        # type: (Dict[str, int]) -> Calendar
        """ Make iCal entries """
        csv_configs = self._generate_configs_from_default(csv_configs)
        self.cal = Calendar()
        self.cal.add('version', '2.0')
        self.cal.add('prodid', 'Custom Rapla to csv to ics converter')
        timezone = Timezone()

        timezone = Component.from_ical(vtimezone_str)
        self.cal.add_component(timezone)
        for row in self.csv_data:
            event = Event()
            event.add('summary', row[csv_configs['CSV_NAME']])
            event.add('dtstart', row[csv_configs['CSV_START_DATE']])
            event.add('dtend', row[csv_configs['CSV_END_DATE']])
            event.add('description', row[csv_configs['CSV_DESCRIPTION']])
            event.add('location', row[csv_configs['CSV_LOCATION']])
            event.add(
                'uid',
                b64encode((
                    row[csv_configs['CSV_START_DATE']].strftime(
                        "%Y-%m-%d %H:%M") +
                    row[csv_configs['CSV_END_DATE']].strftime("%Y-%m-%d %H:%M")
                    + row[csv_configs['CSV_DESCRIPTION']] + '@' +
                    uname()[1]).encode('utf-8')))
            event.add('dtstamp', datetime.datetime.now())
            self.cal.add_component(event)

        return self.cal
Esempio n. 4
0
    def test_cal_Component_from_ical(self):
        # Check for proper handling of TZID parameter of datetime properties
        Component = icalendar.cal.Component
        for component_name, property_name in (('VEVENT', 'DTSTART'), ('VEVENT',
                                                                      'DTEND'),
                                              ('VEVENT', 'RECURRENCE-ID'),
                                              ('VTODO', 'DUE')):
            component_str = 'BEGIN:' + component_name + '\n'
            component_str += property_name + ';TZID=America/Denver:'
            component_str += '20120404T073000\nEND:' + component_name
            component = Component.from_ical(component_str)
            self.assertEqual(str(component[property_name].dt.tzinfo.zone),
                             "America/Denver")

            component_str = 'BEGIN:' + component_name + '\n'
            component_str += property_name + ':'
            component_str += '20120404T073000\nEND:' + component_name
            component = Component.from_ical(component_str)
            self.assertEqual(component[property_name].dt.tzinfo, None)
Esempio n. 5
0
    def test_cal_Component_from_ical(self):
        # Check for proper handling of TZID parameter of datetime properties
        Component = icalendar.cal.Component
        for component_name, property_name in (
            ("VEVENT", "DTSTART"),
            ("VEVENT", "DTEND"),
            ("VEVENT", "RECURRENCE-ID"),
            ("VTODO", "DUE"),
        ):
            component_str = "BEGIN:" + component_name + "\n"
            component_str += property_name + ";TZID=America/Denver:"
            component_str += "20120404T073000\nEND:" + component_name
            component = Component.from_ical(component_str)
            self.assertEqual(str(component[property_name].dt.tzinfo.zone), "America/Denver")

            component_str = "BEGIN:" + component_name + "\n"
            component_str += property_name + ":"
            component_str += "20120404T073000\nEND:" + component_name
            component = Component.from_ical(component_str)
            self.assertEqual(component[property_name].dt.tzinfo, None)
Esempio n. 6
0
    def test_cal_Component_to_ical_parameter_order(self):
        Component = icalendar.cal.Component
        component_str = [b"BEGIN:VEVENT", b"X-FOOBAR;C=one;A=two;B=three:helloworld.", b"END:VEVENT"]
        component = Component.from_ical(b"\r\n".join(component_str))

        sorted_str = component.to_ical().splitlines()
        assert sorted_str[0] == component_str[0]
        assert sorted_str[1] == b"X-FOOBAR;A=two;B=three;C=one:helloworld."
        assert sorted_str[2] == component_str[2]

        preserved_str = component.to_ical(sorted=False).splitlines()
        assert preserved_str == component_str
Esempio n. 7
0
    def test_cal_Component_from_ical(self):
        # Check for proper handling of TZID parameter of datetime properties
        Component = icalendar.cal.Component
        for component_name, property_name in (
            ('VEVENT', 'DTSTART'),
            ('VEVENT', 'DTEND'),
            ('VEVENT', 'RECURRENCE-ID'),
            ('VTODO', 'DUE')
        ):
            component_str = 'BEGIN:' + component_name + '\n'
            component_str += property_name + ';TZID=America/Denver:'
            component_str += '20120404T073000\nEND:' + component_name
            component = Component.from_ical(component_str)
            self.assertEqual(str(component[property_name].dt.tzinfo.zone),
                             "America/Denver")

            component_str = 'BEGIN:' + component_name + '\n'
            component_str += property_name + ':'
            component_str += '20120404T073000\nEND:' + component_name
            component = Component.from_ical(component_str)
            self.assertEqual(component[property_name].dt.tzinfo,
                             None)
Esempio n. 8
0
    def test_cal_Component_to_ical_parameter_order(self):
        Component = icalendar.cal.Component
        component_str = [b'BEGIN:VEVENT',
                         b'X-FOOBAR;C=one;A=two;B=three:helloworld.',
                         b'END:VEVENT']
        component = Component.from_ical(b'\r\n'.join(component_str))

        sorted_str = component.to_ical().splitlines()
        assert sorted_str[0] == component_str[0]
        assert sorted_str[1] == b'X-FOOBAR;A=two;B=three;C=one:helloworld.'
        assert sorted_str[2] == component_str[2]

        preserved_str = component.to_ical(sorted=False).splitlines()
        assert preserved_str == component_str
Esempio n. 9
0
    def test_cal_Component_to_ical_property_order(self):
        Component = icalendar.cal.Component
        component_str = [b'BEGIN:VEVENT',
                         b'DTSTART:19970714T170000Z',
                         b'DTEND:19970715T035959Z',
                         b'SUMMARY:Bastille Day Party',
                         b'END:VEVENT']
        component = Component.from_ical(b'\r\n'.join(component_str))

        sorted_str = component.to_ical().splitlines()
        assert sorted_str != component_str
        assert set(sorted_str) == set(component_str)

        preserved_str = component.to_ical(sorted=False).splitlines()
        assert preserved_str == component_str
Esempio n. 10
0
    def test_cal_Component_to_ical_property_order(self):
        Component = icalendar.cal.Component
        component_str = [
            b'BEGIN:VEVENT', b'DTSTART:19970714T170000Z',
            b'DTEND:19970715T035959Z', b'SUMMARY:Bastille Day Party',
            b'END:VEVENT'
        ]
        component = Component.from_ical(b'\r\n'.join(component_str))

        sorted_str = component.to_ical().splitlines()
        assert sorted_str != component_str
        assert set(sorted_str) == set(component_str)

        preserved_str = component.to_ical(sorted=False).splitlines()
        assert preserved_str == component_str
Esempio n. 11
0
    def convert_from_calendar(dict_calendar):
        data = {
            'format': dict_calendar['format']
        }
        if dict_calendar["format"] == CALENDAR:
            pattern = dict_calendar["pattern"]
            calendar_event = Component.from_ical(
                CalendarUtil.decode_calendar_pattern(pattern)
            )
            if isinstance(calendar_event, Event):
                calendar_event_rule = calendar_event['RRULE']
                data['frequence'] = calendar_event_rule['FREQ'][0]

                if data['frequence'] == MONTHLY and not (
                        'INTERVAL' in calendar_event['RRULE']):
                    data['date'] = ' '.join(
                        str(date)
                        for date in calendar_event_rule['BYMONTHDAY'])

                if data['frequence'] == WEEKLY and not (
                        'INTERVAL' in calendar_event['RRULE']):
                    data['day'] = ' '.join(
                        str(CALENDAR_DAY_MAPPING_DICT[day])
                        for day in calendar_event_rule['BYDAY'])

                if 'BYHOUR' in calendar_event['RRULE']:
                    data['hour'] = ' '.join(
                        str(hour) for hour in calendar_event_rule['BYHOUR'])

                if 'BYMINUTE' in calendar_event['RRULE']:
                    data['minute'] = ' '.join(
                        str(minute)
                        for minute in calendar_event_rule['BYMINUTE'])

                if 'INTERVAL' in calendar_event['RRULE']:
                    data['interval'] = ' '.join(
                        str(interval)
                        for interval in calendar_event_rule['INTERVAL'])

        return data
TZOFFSETFROM:-0800
TZOFFSETTO:-0700
TZNAME:PDT
DTSTART:19700308T020000
RRULE:FREQ=YEARLY;BYMONTH=3;BYDAY=2SU
END:DAYLIGHT
BEGIN:STANDARD
TZOFFSETFROM:-0700
TZOFFSETTO:-0800
TZNAME:PST
DTSTART:19701101T020000
RRULE:FREQ=YEARLY;BYMONTH=11;BYDAY=1SU
END:STANDARD
END:VTIMEZONE"""

timezone = Component.from_ical(vtimezone_str)

weekday_abbrv_converter = {
    "U": "SU",
    "M": "MO",
    "T": "TU",
    "W": "WE",
    "R": "TH",
    "F": "FR",
    "S": "SA"
}


def make_calender(userdata_json):
    cal = Calendar()
    cal.add_component(timezone)