#!/usr/bin/env ruby # Ta-da List export to TaskPaper # a quick hack by Manton Reece # http://www.manton.org/ # Edit this for your own Ta-da List hostname! TADALIST_HOST = "you.tadalist.com" # Don't forget to do "gem install hpricot" require 'net/http' require 'rubygems' require 'hpricot' def get_safari_cookie cookie_plist = File.expand_path '~/Library/Cookies/Cookies.plist' doc = Hpricot File.open(cookie_plist) doc.search("string[text()*='#{TADALIST_HOST}']").each do |k| e = k while e = e.next_sibling if e.inner_text == 'Value' s = e.next_sibling return s.inner_text end end end end def get_html(inCookie, inRequest) h = Net::HTTP.new(TADALIST_HOST, 80) req = Net::HTTP::Get.new inRequest req.add_field 'Cookie', "token=#{inCookie}; PATH=/" response = h.request req response.body end def make_filename(inListTitle) filename = inListTitle filename.gsub! '/', '-' filename.gsub! ':', '-' filename += '.taskpaper' filename end def cleaned_text(inElement) li = inElement li.search('div').remove li.search('input').remove li.search('span').remove t = li.inner_text t.strip! t.gsub! "\n", '' t.gsub! "\r", '' t.gsub! "\t", '' t end def export_lists puts 'Getting Safari cookie...' cookie = get_safari_cookie puts 'Found it! Cookie = ' + cookie puts 'Getting /lists/all' lists_html = get_html cookie, '/lists/all' lists_doc = Hpricot lists_html lists_doc.search('//a').each do |a| href = a.attributes['href'] if href =~ /^\/lists\/show/ list_title = a.inner_html items_incompleted = [] items_completed = [] puts 'Getting ' + href contents_html = get_html cookie, href contents_doc = Hpricot contents_html contents_doc.search('//ul').each do |ul| if ul.attributes['id'] == 'incompleted' ul.search('//li').each do |li| items_incompleted << cleaned_text(li) end elsif ul.attributes['id'] == 'completed' ul.search('//li').each do |li| items_completed << cleaned_text(li) end end end puts 'Writing file for list: ' + list_title f = File.new make_filename(list_title), 'w+' f.print list_title + ":\n" items_incompleted.each do |item| f.print '- ' + item + "\n" end items_completed.each do |item| f.print '- ' + item + " @done\n" end f.close end end puts 'All done!' end export_lists