当前位置: 首页>>代码示例>>Python>>正文


Python Calendar.from_ical方法代码示例

本文整理汇总了Python中icalendar.Calendar.from_ical方法的典型用法代码示例。如果您正苦于以下问题:Python Calendar.from_ical方法的具体用法?Python Calendar.from_ical怎么用?Python Calendar.from_ical使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在icalendar.Calendar的用法示例。


在下文中一共展示了Calendar.from_ical方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: update

# 需要导入模块: from icalendar import Calendar [as 别名]
# 或者: from icalendar.Calendar import from_ical [as 别名]
def update(self):
        self.data['events'] = []
        self.tzutc = tz.tzutc()
        self.tzlocal = tz.tzlocal()
        urls, colors = [], {}
        for cal in self._iter_calendars():
            urls.append(cal.url)
            colors[cal.url] = cal.color
        for result in utils.iter_responses(urls, timeout=5):
            response = result.get('response')
            if response:
                ical = Calendar.from_ical(response.read().decode('utf-8'))
                color = colors[result.get('url')]
                self.data['events'] += self._parse_events(ical, color)
        self.data['events'] = sorted(self.data['events'], key=lambda e:e['start'])
        # Calculate time to next event
        now = datetime.datetime.now()
        next = [e for e in self.data['events'] if e['start'] > now][0]['start'] if self.data['events'] else self.DELTANONE
        if next < now + datetime.timedelta(seconds=self.DEFAULT_INTERVAL*1.5): self.data['next'] = 'Now'
        else: self.data['next'] = utils.natural_time(next-now, 1)
        super(Plugin, self).update() 
开发者ID:pkkid,项目名称:pkmeter,代码行数:23,代码来源:gcal.py

示例2: check_time_format

# 需要导入模块: from icalendar import Calendar [as 别名]
# 或者: from icalendar.Calendar import from_ical [as 别名]
def check_time_format(cls, pattern):
        """Check time format

        :param pattern: The pattern of the icalendar time
        """
        try:
            cal_obj = Calendar.from_ical(cls._decode_calendar_pattern(pattern))
        except Exception:
            msg = (_("The trigger pattern(%s) is invalid") % pattern)
            raise exception.InvalidInput(msg)

        try:
            vevent = cal_obj.walk('VEVENT')[0]
        except Exception:
            msg = (_("The trigger pattern(%s) must include less than one "
                     "VEVENT component") % pattern)
            raise exception.InvalidInput(msg)

        try:
            vevent.decoded('RRULE')
        except Exception:
            msg = (_("The first VEVENT component of trigger pattern(%s) must "
                     "include less than one RRULE property") % pattern)
            raise exception.InvalidInput(msg) 
开发者ID:openstack,项目名称:karbor,代码行数:26,代码来源:calendar_time.py

示例3: fromPage

# 需要导入模块: from icalendar import Calendar [as 别名]
# 或者: from icalendar.Calendar import from_ical [as 别名]
def fromPage(cls, page):
        vevent = super().fromPage(page)
        minDt   = pytz.utc.localize(dt.datetime.min)
        dtstart = page._getMyFirstDatetimeFrom() or minDt
        dtend   = page._getMyFirstDatetimeTo(dtstart) or minDt
        vevent.set('UID',         page.uid)
        vevent.set('DTSTART',     vDatetime(dtstart))
        vevent.set('DTEND',       vDatetime(dtend))
        vevent._setDesc(page.details)
        vevent.set('LOCATION',    page.location)
        vevent.vchildren, exDates = cls.__getExceptions(page)
        if exDates:
            vevent.set('EXDATE', exDates)
        until = page.repeat.until
        if until:
            until = getAwareDatetime(until, dt.time.max, dtend.tzinfo)
            until = until.astimezone(pytz.utc)
        vevent.set('RRULE', vRecur.from_ical(page.repeat._getRrule(until)))
        return vevent 
开发者ID:linuxsoftware,项目名称:ls.joyous,代码行数:21,代码来源:ical.py

示例4: _validate_cal

# 需要导入模块: from icalendar import Calendar [as 别名]
# 或者: from icalendar.Calendar import from_ical [as 别名]
def _validate_cal(self, field, value):
        if not value:
            field.help.setText(field.help_default)
            return value
        url = Plugin.build_url(value)
        response = utils.http_request(url, timeout=2).get('response')
        if not response:
            raise ValidationError('No response from Google.')
        ical = Calendar.from_ical(response.read().decode('utf-8'))
        title = ical.get('x-wr-calname', ical.get('version', ''))
        if not title:
            raise ValidationError('Invalid response from Google.')
        field.help.setText(title)
        return value 
开发者ID:pkkid,项目名称:pkmeter,代码行数:16,代码来源:gcal.py

示例5: _get_ical

# 需要导入模块: from icalendar import Calendar [as 别名]
# 或者: from icalendar.Calendar import from_ical [as 别名]
def _get_ical(url, client):
    res = client.get(url)
    return Calendar.from_ical(res.content) 
开发者ID:webkom,项目名称:lego,代码行数:5,代码来源:test_api.py

示例6: help_test_ical_content_permission

# 需要导入模块: from icalendar import Calendar [as 别名]
# 或者: from icalendar.Calendar import from_ical [as 别名]
def help_test_ical_content_permission(self, ical_content, user):
        """
        Tests that permissions are ok.

        Tests that the user can view every
        event/meeting in the ical result.

        """
        icalendar = Calendar.from_ical(ical_content)
        for event in icalendar.subcomponents:
            eventType, pk, domain = _get_ical_event_meta(event)
            if eventType == "event":
                self.assertTrue(user.has_perm(VIEW, Event.objects.get(id=pk)))
            elif eventType == "meeting":
                self.assertTrue(user.has_perm(VIEW, Meeting.objects.get(id=pk))) 
开发者ID:webkom,项目名称:lego,代码行数:17,代码来源:test_api.py

示例7: from_file

# 需要导入模块: from icalendar import Calendar [as 别名]
# 或者: from icalendar.Calendar import from_ical [as 别名]
def from_file(filename, default_timezone):
        with open(filename) as f:
            data = f.read()
        return ICal(Calendar.from_ical(data), default_timezone) 
开发者ID:In2ItChicago,项目名称:In2ItChicago,代码行数:6,代码来源:ical_reader.py

示例8: from_url

# 需要导入模块: from icalendar import Calendar [as 别名]
# 或者: from icalendar.Calendar import from_ical [as 别名]
def from_url(url, default_timezone):
        session = HttpUtils.get_session()
        r = session.get(url)
        return ICal(Calendar.from_ical(r.text), default_timezone) 
开发者ID:In2ItChicago,项目名称:In2ItChicago,代码行数:6,代码来源:ical_reader.py

示例9: test_ics

# 需要导入模块: from icalendar import Calendar [as 别名]
# 或者: from icalendar.Calendar import from_ical [as 别名]
def test_ics(self):
        self.client.login(username='admin', password='admin')
        response = self.client.get(reverse('staff-schedule') + 'ics/')
        self.assertEqual(response.status_code, 200)
        Calendar.from_ical(response.content) 
开发者ID:PonyConf,项目名称:PonyConf,代码行数:7,代码来源:tests.py

示例10: __init__

# 需要导入模块: from icalendar import Calendar [as 别名]
# 或者: from icalendar.Calendar import from_ical [as 别名]
def __init__(self, start_time, pattern):
        super(ICal, self).__init__(start_time, pattern)
        cal = Calendar.from_ical(self._decode_calendar_pattern(pattern))
        vevent = cal.walk('VEVENT')[0]
        self.dtstart = start_time
        self.min_freq = self._get_min_freq(vevent)
        self.rrule_obj = self._get_rrule_obj(vevent, start_time) 
开发者ID:openstack,项目名称:karbor,代码行数:9,代码来源:calendar_time.py

示例11: load

# 需要导入模块: from icalendar import Calendar [as 别名]
# 或者: from icalendar.Calendar import from_ical [as 别名]
def load(self, request, data):
        if self.page is None:
            raise CalendarNotInitializedError("No page set")

        # Typically, this information will consist of an iCalendar stream
        # with a single iCalendar object.  However, multiple iCalendar
        # objects can be sequentially grouped together in an iCalendar
        # stream.
        try:
            calStream = Calendar.from_ical(data, multiple=True)
        except Exception as e:
            #messages.debug(request, str(e))
            return VResults(error=1)

        self.clear()
        results = VResults()
        for cal in calStream:
            tz = timezone.get_current_timezone()
            zone = cal.get('X-WR-TIMEZONE', None)
            if zone:
                try:
                    tz = pytz.timezone(zone)
                except pytz.exceptions.UnknownTimeZoneError:
                    messages.warning(request, "Unknown time zone {}".format(zone))
            with timezone.override(tz):
                results += self._loadEvents(request, cal.walk(name="VEVENT"))
        return results 
开发者ID:linuxsoftware,项目名称:ls.joyous,代码行数:29,代码来源:ical.py

示例12: get_upcoming_events

# 需要导入模块: from icalendar import Calendar [as 别名]
# 或者: from icalendar.Calendar import from_ical [as 别名]
def get_upcoming_events(self, max_results=10, only_participating=True):
        """
        Get the upcoming events. See
        :func:`~platypush.plugins.calendar.CalendarPlugin.get_upcoming_events`.
        """

        import pytz
        from icalendar import Calendar

        events = []
        try:
            response = requests.get(self.url)
        except Exception as e:
            self.logger.exception(e)
            return events

        if response.ok:
            calendar = None

            try:
                calendar = Calendar.from_ical(response.text)
            except Exception as e:
                self.logger.exception(e)
                return events

            for event in calendar.walk():
                if event.name != 'VEVENT':
                    continue  # Not an event

                event = self._translate_event(event)

                if event['status'] and event['responseStatus'] \
                        and dateutil.parser.parse(event['end']['dateTime']) >= \
                            datetime.datetime.now(pytz.timezone('UTC')) \
                        and (
                            (only_participating
                             and event['status'] == 'confirmed'
                             and event['responseStatus'] in ['accepted', 'tentative'])
                            or not only_participating):
                    events.append(event)
        else:
            self.logger.error("HTTP error while getting {}: {}".format(self.url, response))

        return events


# vim:sw=4:ts=4:et: 
开发者ID:BlackLight,项目名称:platypush,代码行数:49,代码来源:ical.py


注:本文中的icalendar.Calendar.from_ical方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。