Skip to content

Instantly share code, notes, and snippets.

@tkan tkan/
Last active Aug 6, 2018

What would you like to do?
RememberTheMilk - iCal duration/time-estimate parser
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""Small script for parsing the time estate to a correctly displayed enddate in ICS format.
Please do 'pip install ics' before using."""
# Python 2 and 3 switch for importing urllib
from urllib.request import urlopen
except ImportError:
from urllib2 import urlopen
# Python 2 and 3 switch for setting UTF8 as default string encoding
import sys
except (AttributeError, NameError):
from ics import Calendar, Event
from datetime import datetime, timedelta
import dateutil.parser
cal = Calendar(urlopen(url).read().decode('utf-8'))
newCal = Calendar()
i = 0
while i < len(
checkBegin = dateutil.parser.parse(str([i].begin))
# check for presence of time estimate and full date (including hours)
if 'Time estimate' in ([i].description) and checkBegin.hour != 0:
# get the time estimate
s =[i].description
# estimates can be in minutes or hours
hourStart = s.find('Time estimate: PT') + 17
hourEnd = s.find('H', hourStart)
hourDuration = (s[hourStart:hourEnd])
minuteStart = s.find('Time estimate: PT') + 17
minuteEnd = s.find('M', minuteStart)
minuteDuration = (s[minuteStart:minuteEnd])
e = Event() =[i].name
e.location =[i].location
e.uid =[i].uid
e.created =[i].created
e.description =[i].description
endTime = dateutil.parser.parse(str([i].begin))
# switch for minutes and hours; if it's minutes, hourDuration will
# contain the whole description string from the event
if len(hourDuration) > 2:
endTime += timedelta(minutes=int(minuteDuration))
endTime += timedelta(hours=int(hourDuration))
e.begin =[i].begin
e.end = endTime
e = Event() =[i].name
e.location =[i].location
e.uid =[i].uid
e.created =[i].created
e.description =[i].description
e.begin =[i].begin
i += 1
with open('rtm_parsed.ics', 'w') as f:

RememberTheMilk - iCal duration/time-estimate parser

This small script will get your secret iCal events from a URL and parse it in a way that an enddate is added. iCal compatible programs should display the correct length of an event. You will need a (virtual) server with cron jobs.

Install / Use

  1. pip install ics
  2. replace 'INSERT URL HERE' with your secret iCal URL
  3. set up cronjob, e.g. */15 * * * * python3.5
  4. the output file rtm_parsed.ics will be written
  5. point your iCal software to your ics file

Tested in Thunderbird 45.4.0 on Ubuntu 16.04 with Python 3.5; requires at least Python 2.7

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.