Here is a Python script to export Day One journal entries into any text-based format (such as html, markdown, plain text, or Latex).
Note: the Day One Mac app can export to plain text, and in the future the iOS apps will export to PDF. This is for people who need or want extra customization options.
I have always been a fan of the Day One Mac and iOS Apps. I was keeping an electronic journal before Day One came along (in Latex, if you must know), but I quickly changed my ways. Day One makes things easier and more fun.
I switched to Day One quickly, but not without an abundance of caution. The last thing I want is for my journal to be unreadable 5 years from now. I was reassured to see that Day One stores each journal entry as a plist file. Furthermore, the entry itself is 100% certified organic plain text. The rest of the plist is just metadata.
As time passed, Day One added features. Most recently, they added the ability to include photos, location information, and weather. All this talk about new features scared me, because more features almost always means more complication. In this case, there was a good chance the extra complication would make my data less future-proof. But in the end, there was no need for me to worry. These guys are good.
A Day One entry is still a simple plist file. The entry itself is still plain text. Location and weather are just more metadata. Best of all, photos can be included with but not inserted into an entry. There is no need for any markup within the journal entry saying “this is where the photo goes.” You don’t have to base64-encode or link to an external file or any of the other awful things word processors have done when dealing with images. A photo is just another piece of metadata that says “This photo goes with that journal entry.”
I put together a Python script to export my journal entries. It uses a Jinja template to combine my Day One entries into a single file of whatever format I want. A simple template and a few lines of css turned my journal into enough html to fill 80 printed pages:
I wrote it for myself, but I thought others might find it useful, so I have posted it on github.
This part is easy. Just import plistlib
and do
plistlib.readPlist(filename)
This is more complicated, and the main thing I learned by making this script. The following script fills in a Jinja template:
|
|
Loading the template file was a little confusing. First, you set up the environment with a FileSystemLoader
in line 7, which takes one or more search paths as an argument. Then the get_template
command in line 9 searches through all of the paths for the template you are looking for. I could not find a way to just load an arbitrary template file, hence the awkward workaround in line 6.
If you’ve ever used Liquid or any other templating language, Jinja looks pretty familiar. Here is a basic template to produce an html version of my journal:
|
|
Control statements go inside {%...%}
blocks, like the for loop from line 10 to line 26 which loops over all the entries. Recall that the journal
variable is passed to the template from Python (in line 10 of the Python code above).
Variables are inserted into the document using {{...}}
blocks, like the date on line 12 and the photo on line 21. Jinja allows a lot of Python into variable blocks (more than Liquid allows Ruby), which means I can call strftime
to format the date in the way that I want. You see more of this on line 14 with the in
in the if
block, and on line 15 which uses the place
method of the entry
object.
Line 23 shows how to apply a filter to a variable. The text of the variable passed through the markdown
filter. This is a custom filter defined in my Python script, but there are also several built-in filters.