本文整理汇总了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()
示例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)
示例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
示例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
示例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)
示例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)))
示例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)
示例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)
示例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)
示例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)
示例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
示例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: