Skip to content

Instantly share code, notes, and snippets.

@alexpgates
Created April 6, 2011 20:05
Show Gist options
  • Save alexpgates/906408 to your computer and use it in GitHub Desktop.
Save alexpgates/906408 to your computer and use it in GitHub Desktop.
Use DayOne data with php.
<?php
// DayOne is a nice little journaling app for iOS / Mac (available via App Store).
// This code requires php_class_lib available here: https://github.com/jsjohnst/php_class_lib
include('php_class_lib/classes/parsers/plist/PlistParser.inc');
// grab filenames for all of your journal entries
$entries = array();
if ($handle = opendir('/path/to/your/Journal.dayone/entries')) {
while (false !== ($file = readdir($handle))) {
if($file != '.' && $file != '..'){
$entries[] = $file;
}
}
closedir($handle);
}
// loop through each entry and display title, date, and content
foreach($entries as $entry){
$parser = new plistParser();
$plist = $parser->parseFile("/path/to/dayone/Journal.dayone/entries/$entry");
$stamp = strtotime($plist['Creation Date']);
$entry_text = nl2br($plist['Entry Text']);
$entry_year = date('Y', $stamp);
$entry_month = date('F', $stamp);
$entry_date = date('d', $stamp);
?>
<h1><?php echo $entry_month.' '.$entry_date.', '.$entry_year; ?> </h1>
<p><?php echo $entry_text; ?></p>
<?php } ?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment