This code publishes an iCal file that can be subscribed to in Google Calendar. They change the way they interpret iCal data occasionally, so this may break, I'll try to keep it up to date.
There is some crazy string replace stuff going on there, I haven't yet convinced vObject to format things properly.
Feedback welcome.
*Note: this works for my existing feeds, but if I add a new feed to GCal, the timezones are incorrect, I'm working on that.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | cal = vobject.iCalendar()
cal.add('prodid').value='-//'+CALENDAR_NAME+'//PYVOBJ_'+CALENDAR_SHORT_NAME+'-Cal//EN'
cal.add('VTIMEZONE').tzinfo=dateutil.tz.tzlocal()
#cal.add('CALSCALE').value='GREGORIAN'
#cal.add('METHOD').value='PUBLISH'
#cal.add('X-WR-CALNAME').value=request.build_absolute_uri()
#cal.add('X-WR-TIMEZONE').value='Australia/Sydney'
for event in events:
ev = cal.add('vevent')
ev.add('uid').value = str(event.id)+'@'+CALENDAR_SHORT_NAME
dts=ev.add('dtstart')
dts.value = <datetime>
dts.params['tzid']='E'
dte=ev.add('dtend')
dte.value = <datetime>
dte.params['tzid']='E'
ev.add('summary').value = <str>
ev.add('description').value = <str>
ev.add('location').value = <str>
ev.add('status').value = <str:CONFIRMED|TENTATIVE|CANCELLED>
alarm=ev.add('valarm')
alarm.add('value').value='DURATION'
alarm.add('trigger').value=datetime.timedelta(minutes=-30)
text=cal.serialize()
text=text.replace('tzid=E', 'TZID=EST')
if False: text=text.replace('BEGIN:VTIMEZONE', """CALSCALE:GREGORIAN
METHOD:PUBLISH
X-WR-CALNAME:%s
X-WR-TIMEZONE:Australia/Sydney
BEGIN:VTIMEZONE""" % (request.build_absolute_uri()))
return HttpResponse(text, mimetype='text/calendar')
|
More like this
- Stuff by NixonDash 1 month ago
- Add custom fields to the built-in Group model by jmoppel 3 months ago
- Month / Year SelectDateWidget based on django SelectDateWidget by pierreben 6 months, 2 weeks ago
- Python Django CRUD Example Tutorial by tuts_station 7 months ago
- Browser-native date input field by kytta 8 months, 2 weeks ago
Comments
Or use django-cal for iCalendar files generation a la
django.contrib.syndication
.#
Please login first before commenting.