Paul A. Kusisto

Convert Sleep As Android Data to iCal Calendar File

I will likely be easing up on the python-code-to-convert-from-one-representation-of-data-to-another scripts here, but this quick project was too cool not to share.
I have been using the excellent Sleep As Android app for years, (I have almost 1000 sleep records saved in the app) and I’ve loved the great tools that the Urbandroid Team provides for visualizing your sleep, but there was one simple tool that I still wanted: an “export to calendar” option.

I am forever tied to my calendar, and have always thought it would be nice to be able to see (when looking back at a particular moment in time) when I was asleep. With that goal in mind, I wrote the “first draft” script linked below. I’m posting this script here not because it’s perfect, (it’s absolutely not) but because it works! This code takes in a Sleep As Android .csv backup file, and converts it into an iCal (.ics) calendar file, which can be imported into almost any electronic calendar (iCloud Calendar, Google Calendar, Outlook, etc.).

I’ve been loving being able to see the connections between my day-to-day schedule, and my sleep schedule. I expect to do more rigorous data analysis in the future, but this code is all I’ll be releasing for now.

To use it, first download your data from the “iCloud” platform (or export it manually from within the app). I have my backups synced with Google Drive, so I can download my records from there. Once you have downloaded your data, (labeled “Sleep as Android Data.csv”) simply drop it in the same folder as the python script linked below, run the script, (with Python 2.7 installed, of course) and you should see a “sleepCal.ics” file appear! This file can be imported into nearly any modern calendar software for viewing.

(Command line arguments can be used to specify input and output paths, use “SleepAsAndroidToCalendar.py -h” for more information.)

Again, this code is NOT final - it’s a rough draft. It has several known issues, (it doesn’t respect time zones, for one thing) but it works, and I’m excited to develop it further!

Without further ado, here is the code, for you to try it out yourself: https://github.com/PaulKusisto/SleepAsAndroidToCalendar