-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathohlife2dayone.pl
executable file
·68 lines (56 loc) · 2.08 KB
/
ohlife2dayone.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#!/usr/bin/env perl
# ohlife2dayone.pl
# BooneJS (http://boonejs.tumblr.com)
# Use and modify freely, attribution appreciated
#
# This script works with the Day One command line utility found in the
# Application Package. The input to this script is the exported text file
# from OhLife.com (https://ohlife.com/export). Clicking the "Export" button
# will save a .txt file to ~/Downloads/ohlife_YYYYMMDD.txt.
#
# Script idea was born after reading http://brettterpstra.com/logging-with-day-one-geek-style/
#
# Usage:
# 1. Save this file someplace (~/Downloads, perhaps?)
# 2. Open a Terminal in OS X (/Applications/Utilities/Terminal.app)
# 3. chmod +x ~/Downloads/ohlife2dayone.pl
# 4. cat ~/Downloads/ohlife_YYYYMMDD.txt | ~/Downloads/ohlife2dayone.pl
use warnings;
use strict;
my $time = "8:00PM"; # default time for Day One
my $savedDate = "";
my $message = "";
my $justCapturedDate = 0;
while(<>) {
my $line = $_;
# Exported file is in DOS format; remove any excess carriage returns
$line =~ s/\r//g;
# If the line contains a date,
if($line =~ /(\d{4}-\d{2}-\d{2})/) {
# Reached a new date. If there's a current date, call dayone and enter the information.
chomp($line);
if($savedDate ne "") {
# dayone is installed to /usr/local/bin. Download from http://dayoneapp.com/downloads/dayone-cli.pkg
system("echo \"$message\" | /usr/local/bin/dayone -d=\"$savedDate $time\" new") ;
}
# If date is specified as YYYY-MM-DD, dayone seems to assume date/time is UTC and subtract for your timezone.
# For instance, UTC -6 (Central Time Zone), so 8:00PM shows up at 2:00PM in Day One.
# However, YYYY/MM/DD seems to assume date/time is current time zone.
$line =~ s/-/\//g;
$savedDate = $line;
$message = ""; # reset message
$justCapturedDate = 1;
}
else {
if ($justCapturedDate == 1 ) {
$justCapturedDate = 0;
next;
}
# Need to escape any " in $line, otherwise system() will interpret it as the end of the string to execute.
$line =~ s/"/\\"/g;
# Escape $
$line =~ s!\$!\\\$!g;
# Append string to the message.
$message = $message . $line . "\n";
}
}