Skip to content

Instantly share code, notes, and snippets.

@craigeley
Last active August 29, 2015 13:57
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save craigeley/9494663 to your computer and use it in GitHub Desktop.
Save craigeley/9494663 to your computer and use it in GitHub Desktop.
This script finds TaskPaper items in a specific folder completed with this format: "@done(yyyy-mm-dd HH:MM)", moves and converts them into Sifttter format, and then deletes them.
#!/usr/bin/env ruby
# encoding: utf-8
require 'time'
files = Dir["/Users/USERNAME/Dropbox/Listacular/*.taskpaper"]
projects = []
found_completed = false
files.each do |file|
if File.exists?(file.strip)
f = File.open(file.strip, encoding: 'UTF-8')
project = File.basename(file).gsub(/.taskpaper/, ' ').strip
lines = f.read
f.close
item = ''
content = ''
date = ''
time = ''
lines.each_line do |line|
if line =~ /&/
line.gsub!(/&/, 'and')
end
if line =~ /@done/
item = line.gsub(/@done\(.*\)/,'').gsub(/@due\(.*\)/,'').gsub(/-./, '').strip
/@done\((?<t>.*)\)/ =~ line
day = Time.parse(t)
date = day.strftime('%B %d, %Y')
time = day.strftime("%I:%M%p")
open('/Users/USERNAME/Dropbox/IFTTT/' + "#{project}" + '.taskpaper', 'a') { |f|
f.puts "- #{date} at #{time} - #{item} @done" + "\n"}
found_completed = true
end
if line !~ /@done/
content += line.gsub(/\s*@/, ' @')
end
end
if found_completed
open('/Users/USERNAME/Dropbox/Listacular/' + "#{project}" + '.taskpaper', 'w+') { |f2|
f2.puts "#{content}"}
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment