本文整理汇总了Python中vobject.iCalendar函数的典型用法代码示例。如果您正苦于以下问题:Python iCalendar函数的具体用法?Python iCalendar怎么用?Python iCalendar使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了iCalendar函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_compare_summary_diff2
def test_compare_summary_diff2():
first = iCalendar()
first_vevent = first.add('vevent')
first_vevent.add('summary').value = "Foo"
second = iCalendar()
second.add('vevent')
second_out = iCalendar()
compare(first, second, second_out)
assert len(first.contents) == 1
assert len(second_out.contents) == 1
示例2: test_compare_simple
def test_compare_simple():
first = iCalendar()
first.add('vevent')
second = iCalendar()
second.add('vevent')
second_out = iCalendar()
compare(first, second, second_out)
assert len(first.contents) == 0
assert len(second_out.contents) == 0
示例3: test_compare_dtend
def test_compare_dtend():
first = iCalendar()
first_vevent = first.add('vevent')
first_vevent.add('dtstart').value = datetime(2001, 1, 1, 10, 0)
first_vevent.add('dtend').value = datetime(2001, 1, 1, 11, 0)
second = iCalendar()
second_vevent = second.add('vevent')
second_vevent.add('dtstart').value = datetime(2001, 1, 1, 10, 0)
second_vevent.add('dtend').value = datetime(2001, 1, 1, 11, 0)
second_out = iCalendar()
compare(first, second, second_out)
assert len(first.contents) == 0
assert len(second_out.contents) == 0
示例4: test_compare_dtend_duration_diff
def test_compare_dtend_duration_diff():
first = iCalendar()
first_vevent = first.add('vevent')
first_vevent.add('dtstart').value = datetime(2001, 1, 1, 10, 0)
first_vevent.add('dtend').value = datetime(2001, 1, 1, 11, 0)
second = iCalendar()
second_vevent = second.add('vevent')
second_vevent.add('dtstart').value = datetime(2001, 1, 1, 10, 0)
second_vevent.add('duration').value = timedelta(hours=2)
second_out = iCalendar()
compare(first, second, second_out)
assert len(first.contents) == 1
assert len(second_out.contents) == 1
示例5: test0050create_event_attendee
def test0050create_event_attendee(self):
'Create event with attendee'
ical = vobject.iCalendar()
vevent = ical.add('vevent')
vevent.add('summary')
vevent.summary.value = 'Test event with attendee'
vevent.add('dtstart')
vevent.dtstart.value = datetime.datetime.now() + relativedelta(days=10)
vevent.add('dtend')
vevent.dtend.value = datetime.datetime.now() + relativedelta(days=10,
hours=4)
vevent.add('organizer')
vevent.organizer.value = '%[email protected]' % user
attendees = []
for name in ('foo', 'bar'):
attendee = vobject.base.ContentLine('ATTENDEE', [], '')
attendee.partstat_param = 'TENTATIVE'
attendee.value = 'MAILTO:%[email protected]' % name
attendees.append(attendee)
vevent.attendee_list = attendees
caldav.Event(self.client, data=ical.serialize(),
parent=self.calendar).save()
Event = Model.get('calendar.event')
owner_event, = Event.find([
('calendar.owner.email', '=', '%[email protected]' % user),
('summary', '=', vevent.summary.value),
])
attendee_event, = Event.find([
('calendar.owner.email', '=', '[email protected]'),
])
self.assertEqual(attendee_event.uuid, owner_event.uuid)
示例6: action_ical
def action_ical(request,username):
user = get_object_or_404(User,username=username)
todos = user.actionitem_todo.filter(done=False)
filename = "JK_Gestor_ActionItems.ics"
import vobject
import datetime
cal = vobject.iCalendar()
cal.add('method').value = 'PUBLISH' # IE/Outlook needs this
for actionitem in todos:
vtodo = cal.add('vtodo')
vtodo.add('summary').value = actionitem.title
# TODO: escaping this stuff
# vtodo.add('description').value = actionitem.description
vtodo.add('due;value=date').value = actionitem.due_date.strftime("%Y%m%d")
vtodo.add('priority').value = "0"
icalstream = cal.serialize()
response = HttpResponse(icalstream, mimetype='text/calendar')
response['Filename'] = filename # IE needs this
response['Content-Disposition'] = 'attachment; filename='+filename
return response
示例7: events_calendar
def events_calendar(request, public=True):
cache_key = "calendar_%s" % ("public" if public else "private")
cached = cache.get(cache_key)
if cached:
return cached
cal = vobject.iCalendar()
cal.add("X-WR-CALNAME").value = "Air Mozilla Public Events" if public else "Air Mozilla Private Events"
now = datetime.datetime.utcnow().replace(tzinfo=utc)
events = list(
Event.objects.approved()
.filter(start_time__lt=now, public=public)
.order_by("-start_time")[: settings.CALENDAR_SIZE]
)
events += list(
Event.objects.approved()
.filter(start_time__gte=now, public=public)
.order_by("start_time")[: settings.CALENDAR_SIZE]
)
base_url = "%s://%s/" % (request.is_secure() and "https" or "http", RequestSite(request).domain)
for event in events:
vevent = cal.add("vevent")
vevent.add("summary").value = event.title
vevent.add("dtstart").value = event.start_time
vevent.add("dtend").value = event.start_time + datetime.timedelta(hours=1)
vevent.add("description").value = unhtml(short_desc(event))
if event.location:
vevent.add("location").value = event.location.name
vevent.add("url").value = base_url + event.slug + "/"
icalstream = cal.serialize()
response = http.HttpResponse(icalstream, mimetype="text/calendar; charset=utf-8")
filename = "AirMozillaEvents%s.ics" % ("Public" if public else "Private")
response["Content-Disposition"] = "inline; filename=%s" % filename
cache.set(cache_key, response)
return response
示例8: make_ical
def make_ical(data, sources):
calweek_regex = re.compile(r'^(\d+)\. KW$')
time_regex = re.compile(r'^(\d+)\.(\d+) - (\d+)\.(\d+)$')
room_regex = re.compile(r'^(.*) - (.*)$')
times = {}
for time in data[0]['order']:
matches = time_regex.match(time)
if not matches:
raise CannotParseTime("String was: %s" % time)
newtime = {'start': rd.relativedelta(hour=int(matches.group(1)), minute=int(matches.group(2))),
'end': rd.relativedelta(hour=int(matches.group(3)), minute=int(matches.group(4)))}
times[time] = newtime
calendar = vobject.iCalendar()
cat_map = {u"V": u"Vorlesung",
u"Ü": u"Übung",
u"P": u"Praktikum"}
begin_date = None
for week in data:
if not begin_date:
calweek = calweek_regex.match(week['week'])
if not calweek:
raise CannotParseCalweek("String was: %s" % week['week'])
calweek = int(calweek.group(1))
begin_date = datetime.now() + rd.relativedelta(month=1, day=4, weekday=rd.MO(-1), weeks=+(calweek - 1), hour=0, minute=0, second=0, microsecond=0)
else:
begin_date = begin_date + rd.relativedelta(weeks=+1)
for day in range(0,5):
day_data = week['data'][day]
day_date = begin_date + rd.relativedelta(days=+day)
for time in day_data:
for entry in day_data[time]:
event = calendar.add('vevent')
event.add('dtstart').value = day_date + times[time]["start"]
event.add('dtend').value = day_date + times[time]["end"]
cat = ""
if entry["typ"][0] in cat_map:
event.add('categories').value = ["UNI:" + cat_map[entry["typ"][0]]]
cat = " (%s)" % cat_map[entry["typ"][0]]
teacher = entry["room"]
room_match = room_regex.match(entry["room"])
if room_match:
event.add('location').value = room_match.group(1).strip()
teacher = room_match.group(2)
event.add('summary').value = "%s%s" % (entry['name'], cat)
event.add('description').value = u"Kürzel: %s\nDozent: %s\nVeranstaltungsdyp: %s\nQuelle:%s" % (entry["short"],
teacher,
entry["typ"],
sources[entry['source']].string)
uid = uuid.uuid3(uuid.NAMESPACE_DNS, '%s %s' % (str(event.location.value),
str(event.dtstart.value)))
event.add("uid").value = str(uid)
return calendar.serialize()
示例9: ical_feed2
def ical_feed2(request):
'''
Generates an ical sync of all events in the future
'''
cal = vobject.iCalendar()
tz = timezone(TIME_ZONE)
utc = timezone('GMT')
# IE/Outlook needs this:
cal.add('method').value = 'PUBLISH'
# Only publish events in the future
for event in filter(lambda e: e.is_in_future(),Event.objects.order_by('start').exclude(displayFrom__gte=datetime.now())):
total = str(event.signup_total()) if event.signup_total() else u'\u221E'
signups = u' [%i/%s]' % (event.signup_count(),total) if event.has_signups() else u''
vevent = cal.add('vevent')
vevent.add('summary').value = event.type.name + (' - ' + event.shortDescription if event.shortDescription else event.type.name) + signups
vevent.add('location').value = str(event.location)
vevent.add('dtstart').value = tz.localize(event.start).astimezone(utc)
vevent.add('dtend').value = tz.localize(event.finish).astimezone(utc)
vevent.add('dtstamp').value = tz.localize(event.creation_time()).astimezone(utc) # again, for Outlook
vevent.add('description').value = event.longDescription
vevent.add('sequence').value = str(event.update_count()) # for updates
vevent.add('categories').value = [event.type.get_target_display()]
url = "http://%s/events/details/%i/" % (Site.objects.get_current() , event.id)
vevent.add('uid').value = url
vevent.add('url').value = url
response = HttpResponse(cal.serialize(), mimetype='text/calendar; charset=UTF-8')
response['Filename'] = 'compsoc.ics' # IE needs this
response['Content-Disposition'] = 'attachment; filename=compsoc.ics'
return response
示例10: calendar_ics
def calendar_ics(self,**kwargs):
#Build list of courses.
courses = []
for i in range(1,MAX_COURSES +1):
if kwargs['course%dname' % i] == '':
continue
courses.append({
'name':kwargs['course%dname' %i],
'location':kwargs['course%dlocation' %i],
'slot':kwargs['course%dslot' %i],
'tutlocation':kwargs['tutorial%dlocation' %i],
'tutslot':kwargs['tutorial%dslot' %i]
})
for course in courses:
if course['slot'] not in self.slots:
try:
self.parseTimes(course['slot'])
except:
return self.invalidSlot(course)
if course['tutslot'] != '' and course['tutslot'] not in self.slots:
try:
self.parseTimes(course['tutslot'])
except:
return self.invalidSlot(course)
cal = vobject.iCalendar()
for course in courses:
self.addToCalendar(cal,course)
cherrypy.response.headers['Content-Type']= 'text/calendar'
return cal.serialize()
示例11: xacts_cal
def xacts_cal(request, account):
parameters = ['-F', '%(date)\t%(payee)\t%(amount)\n', '-d', 'd>=[today]-14 & d < [tomorrow]', '--sort', 'd', 'reg', '^' + account]
output = runledger(parameters)
cal = vobject.iCalendar()
cal.add('method').value = 'PUBLISH' # IE/Outlook needs this
cal.add('x-wr-calname').value = prettyname(account) + " Events"
cal.add('X-WR-TIMEZONE').value = "US/Pacific"
cal.add('X-WR-CALDESC').value = "Daily events of account " + account
for line in output.split('\n'):
if(line == ""):
continue
date, payee, amount = line.split('\t')
vevent = cal.add('vevent')
vevent.add('summary').value = payee + "\t" + amount
vevent.add('dtstart').value = datetime.datetime.strptime(date, "%Y/%m/%d").date()
icalstream = cal.serialize()
response = HttpResponse(icalstream, mimetype='text/calendar')
response['Filename'] = 'ledger-events.ics' # IE needs this
response['Content-Disposition'] = 'attachment; filename=ledger-events.ics'
return response
示例12: icalFeed
def icalFeed(request, tag):
cal = vobject.iCalendar()
cal.add('CALSCALE').value = 'GREGORIAN'
cal.add('METHOD').value = 'PUBLISH'
cal.add('X-WR-CALNAME').value = tag + ' Events'
cal.add('X-WR-TIMEZONE').value = 'America/New_York'
cal.add('X-WR-CALDESC').value = 'Calendar of campus events. Filter:'+tag
filteredEvents = Event.objects.filter(event_date_time_end__lte=datetime.now()).order_by('event_date_time_start')
if not tag == "All":
filteredEvents = filteredEvents.filter(event_cluster__cluster_tags__category_name=tag)
for event in filteredEvents[0:200]:
vevent = cal.add('VEVENT')
vevent.add('SUMMARY').value = smart_unicode(str(event))
vevent.add('DTSTART').value = event.event_date_time_start
vevent.add('DTEND').value = event.event_date_time_end
vevent.add('LOCATION').value = unicode(event.getGCalLocation())
vevent.add('DESCRIPTION').value = unicode(event.getGCalClusterDes() + "\n\n" + event.getGCalEventDes())
icalstream = cal.serialize()
response = HttpResponse(icalstream, mimetype='text/calendar')
response['Content-Type'] = 'text/calendar; charset=utf-8'
# response['Transfer-Encoding'] = 'chunked'
response['Connection'] = 'close'
response['Cache-Control'] = 'no-cache, no-store, max-age=0, must-revalidate'
response['Pragma'] = 'no-cache'
return response
示例13: __init__
def __init__(self, list):
if not list:
raise RuntimeError("You must define at least one GitHubIssue \
object")
self.cal = vobject.iCalendar()
for issues in list:
if type(issues) != GitHubIssues:
raise RuntimeError("All arguments have to be GitHubIssues \
objects")
for issue in issues.get():
todo = self.cal.add('vtodo')
todo.add('summary').value = issue['title']
todo.add('description').value = issue['body']
# FIXME: repo name as a location? any better ideas?
todo.add('location').value = issues.repo
created = date(issue['created_at'])
todo.add('dtstart').value = \
todo.add('dtstamp').value = \
todo.add('created').value = created
todo.add('last-modified').value = date(issue['updated_at'])
# if the issue has a milestone with due on date
if issue['milestone']:
if not issue['milestone']['due_on']:
continue
todo.add('due').value = date(issue['milestone']['due_on'])
示例14: get
def get(self, request, *args, **kwargs):
cal = vobject.iCalendar()
cal.add('x-wr-calname').value = 'Studentenportal Events'
cal.add('x-wr-timezone').value = 'Europe/Zurich'
for event in models.Event.objects.all():
vevent = cal.add('vevent')
vevent.add('summary').value = event.summary
vevent.add('description').value = event.description
if event.start_time:
dtstart = datetime.datetime.combine(event.start_date,
event.start_time)
else:
dtstart = event.start_date
vevent.add('dtstart').value = dtstart
if event.end_date or event.end_time:
if not event.end_date:
dtend = datetime.datetime.combine(event.start_date,
event.end_time)
elif event.end_time:
dtend = datetime.datetime.combine(event.end_date,
event.end_time)
else:
dtend = datetime.datetime.combine(
event.end_date, datetime.time(23, 59, 59))
vevent.add('dtend').value = dtend
if event.author:
vevent.add(
'comment').value = 'Erfasst von %s' % event.author.name()
return HttpResponse(cal.serialize(), content_type='text/calendar')
示例15: create_collection
def create_collection(cls, href, collection=None, tag=None):
folder = os.path.expanduser(
cls.configuration.get("storage", "filesystem_folder"))
path = path_to_filesystem(folder, href)
if not os.path.exists(path):
os.makedirs(path)
if not tag and collection:
tag = collection[0].name
self = cls(href)
if tag == "VCALENDAR":
self.set_meta("tag", "VCALENDAR")
if collection:
collection, = collection
for content in ("vevent", "vtodo", "vjournal"):
if content in collection.contents:
for item in getattr(collection, "%s_list" % content):
new_collection = vobject.iCalendar()
new_collection.add(item)
self.upload(uuid4().hex, new_collection)
elif tag == "VCARD":
self.set_meta("tag", "VADDRESSBOOK")
if collection:
for card in collection:
self.upload(uuid4().hex, card)
return self