-
-
Save ammonkc/8423411 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/ruby | |
# Sifttter: An IFTTT-to-Day One Logger by Craig Eley 2014 <http://craigeley.com> | |
# Based on tp-dailylog.rb by Brett Terpstra 2012 <http://brettterpstra.com> | |
# | |
# Notes: | |
# * Uses `mdfind` to locate a specific folder of IFTTT-generated text files changed in the last day | |
# * The location of your folder should be hardcoded in line 53 | |
# * Scans leading timestamps in each line matching today's date | |
# * Does not alter text files in any way | |
# * Changes ampersand ('&') to 'and' so the script keeps running | |
# * Does not require the Day One CLI tool | |
# * Only generates report if there are completed tasks found | |
# * Compiles all results into a single Day One entry | |
# * It's configured to locate a Dropbox-synced journal, so | |
# * If you use iCloud you'll can just uncomment lines 26 and 27, and comment line 28 | |
# * To set the Day One entries to starred, just change `starred = false` to true on line 24 | |
require 'time' | |
require 'erb' | |
require 'date' | |
uuid = %x{uuidgen}.gsub(/-/,'').strip | |
datestamp = Time.now.utc.iso8601 | |
starred = false | |
dayonedir = %x{ls ~/Library/Mobile\\ Documents/|grep dayoneapp}.strip | |
dayonepath = "~/Library/Mobile\ Documents/#{dayonedir}/Documents/Journal_dayone/entries/" | |
# dayonepath = "/Users/ammonkc/Dropbox/Apps/Day\ One/Journal.dayone/entries/" | |
template = ERB.new <<-XMLTEMPLATE | |
<?xml version="1.0" encoding="UTF-8"?> | |
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | |
<plist version="1.0"> | |
<dict> | |
<key>Creation Date</key> | |
<date><%= datestamp %></date> | |
<key>Entry Text</key> | |
<string><%= entrytext %></string> | |
<key>Starred</key> | |
<<%= starred %>/> | |
<key>Tags</key> | |
<array> | |
<string>daily logs</string> | |
</array> | |
<key>UUID</key> | |
<string><%= uuid %></string> | |
</dict> | |
</plist> | |
XMLTEMPLATE | |
today = Time.now().strftime('%B %d, %Y') | |
cdate = Time.now().strftime('%m/%d/%Y') | |
files = %x{mdfind -onlyin /Users/ammonkc/Dropbox/Apps/IFTTT/Sifttter 'kMDItemContentModificationDate >= "$time.today(-1)"' | grep -v -i daily | sort} | |
projects = [] | |
files.split("\n").each do |file| | |
if File.exists?(file.strip) | |
f = File.open(file.strip, encoding: 'UTF-8') | |
lines = f.read | |
f.close | |
project = "### " + File.basename(file).gsub(/^.*?\/([^\/]+)$/,"\\1") + "\n" | |
found_completed = false | |
lines.each_line do |line| | |
if line =~ /&/ | |
line.gsub!(/[&]/, 'and') | |
end | |
if line =~ /#{today}/ | |
found_completed = true | |
project += line.gsub(/@done/,'').gsub(/#{today}.../,'').gsub(/@br/,"\n").strip + "\n" | |
end | |
end | |
end | |
if found_completed | |
projects.push(project) | |
end | |
end | |
def e_sh(str) | |
str.to_s.gsub(/(?=["\\])/, '\\') | |
end | |
if projects.length <=0 | |
abort "No entries found" | |
end | |
if projects.length > 0 | |
entrytext = "# Daily Log for #{today}\n\n" | |
projects.each do |project| | |
entrytext += project.gsub(/.txt/, ' ') + "\n\n" | |
end | |
fh = File.new(File.expand_path(dayonepath+uuid+".doentry"),'w+') | |
fh.puts template.result(binding) | |
fh.close | |
puts "Entry logged for #{today}" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment