Skip to content

Instantly share code, notes, and snippets.

@alancwoo
Created March 13, 2019 09:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alancwoo/9e9bf5a3d0fa2859b7f84d1f29413082 to your computer and use it in GitHub Desktop.
Save alancwoo/9e9bf5a3d0fa2859b7f84d1f29413082 to your computer and use it in GitHub Desktop.
Print travel dates from Google Calendar export
#!/usr/bin/python3
""" Travel Calendar Parser
Export ics from Google Calendar and pass filename as argument
pip3 install ics
python3 travel_dates.py input_file.ics
"""
import sys
from ics import Calendar
DATE_FORMAT = "%d-%m-%Y"
filename = sys.argv[1]
file = open(filename, "r")
c = Calendar(file)
eventsSorted = sorted(c.events, key=lambda x: x.begin)
for e in eventsSorted:
if e.all_day:
print("{:<15} | {} → {} | {:>7}".format(e.name, e.begin.strftime(DATE_FORMAT), e.end.strftime(DATE_FORMAT), str(e.duration).replace(", 0:00:00", "")))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment