Skip to content

Instantly share code, notes, and snippets.

@Quantum-cross
Created May 14, 2014 15:19
Show Gist options
  • Save Quantum-cross/798a85d978e3c3aac3e1 to your computer and use it in GitHub Desktop.
Save Quantum-cross/798a85d978e3c3aac3e1 to your computer and use it in GitHub Desktop.
# coding: utf-8
# In[1]:
from datetime import timedelta, datetime, tzinfo
from pytz import timezone
from icalendar import Calendar, Event, Alarm
import uuid
from os import chdir
# In[3]:
def display(cal):
return cal.to_ical().replace('\r\n', '\n').strip()
# In[5]:
prefix = """BEGIN:VCALENDAR
VERSION:2.0
BEGIN:VTIMEZONE
TZID:America/New_York
X-LIC-LOCATION:America/New_York
BEGIN:DAYLIGHT
TZOFFSETFROM:-0500
TZOFFSETTO:-0400
TZNAME:EDT
DTSTART:19700308T020000
RRULE:FREQ=YEARLY;BYDAY=2SU;BYMONTH=3
END:DAYLIGHT
BEGIN:STANDARD
TZOFFSETFROM:-0400
TZOFFSETTO:-0500
TZNAME:EST
DTSTART:19701101T020000
RRULE:FREQ=YEARLY;BYDAY=1SU;BYMONTH=11
END:STANDARD
END:VTIMEZONE
"""
suffix = """
END:VCALENDAR"""
# In[7]:
chdir('/home/quantum/.config/vdir/calendars/reminders.ics')
tz = timezone('America/New_York')
now = datetime.now(tz)
tomorrow = now + timedelta(days=1)
uid = uuid.uuid4()
event = Event()
event.add('created', now)
event.add('last-modified', now)
event.add('summary', 'Test reminder')
event.add('transp','OPAQUE')
event.add('dtstart', tomorrow)
event.add('dtend', tomorrow + timedelta(hours=1))
event.add('dtstamp', tomorrow)
event.add('uid',uid)
alarm = Alarm()
alarm.add('action', 'DISPLAY')
alarm['TRIGGER;VALUE=DURATION'] = 'PT0S'
alarm['DESCRIPTION'] = 'Default Mozilla Description'
event.add_component(alarm)
print display(event)
icsdata = prefix+display(event)+suffix
print str(uid)+'.ics'
f = open(str(uid)+'.ics', 'w')
f.write(icsdata)
f.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment