Published in: Ruby
URL: http://rememberthemilk.com
Hacked up Ruby script that downloads all the tasks from vitalist and mails them as new tasks to rememberthemilk.
NOTE: you need to change some values in the source to make this work. You also need to comment and uncomment some parts if you want to store stuff locally first, or use this as a one-time script.
require 'net/http' require 'net/smtp' require 'rexml/document' def send_email(from, from_alias, to, to_alias, subject, message) msg = <<END_OF_MESSAGE From: #{from_alias} <#{from}> To: #{to_alias} <#{to}> Subject: #{subject} #{message} END_OF_MESSAGE #Obviously change this into your own smtp server. Net::SMTP.start('smtp.chello.nl') do |smtp| smtp.send_message msg, from, to end end def send_task_mail(body, projects, contexts , tags) from = '' #Where are we sending from, emailaddy? from_alias = '' #Our name #to = 'foo@webschuur.com' #debugging #to_alias = 'Bèr Kessels' to = '' #Your RTM *single item* Inbox e-mailadress. Batchmails don't seem to accept tags etc. to_alias = 'RTM inbox' projects.each { |project| tags << "+" + project.strip unless project.strip.empty? #Add a +-sign to the project. That way we have nice RTM tags for projects } contexts.each { |context| tags << '@'+context.strip unless context.strip.empty? #Add a @-sign to the project. That way we have nice RTM tags for contexts } #Now lets make a string from the tags. tags = tags.join(', ') message = <<END_OF_MESSAGE Tags: #{tags} END_OF_MESSAGE send_email(from, from_alias, to, to_alias, body, message) end # #Your Vitalist API key, find it a vitalist.com # key = '' # # #Web url for the XML # url = "http://my.vitalist.com/services/api/export/#{key}" # # # get the XML data as a string # xml_data = Net::HTTP.get_response(URI.parse(url)).body # # Because of debugging, I store the vitalist XML in a local file. Saves Bandwith and time. # my_file = File.new("/home/ber/tmp/vitalistdump.xml", APPEND) # my_file.puts xml_data # In case we Don't store the data in a temporary file locally, then we use this to turn the XML string into a REMXL object. #doc = REXML::Document.new xml_data # In case we read from a local file (see above) we turn that file into a REMXL object doc = REXML::Document.new File.new("/home/ber/tmp/vitalistdump.xml") doc.elements.each("response/items/item") { |item| #First we see if this is not an already finished item archived = FALSE if (! item.elements["complete_date"].text.nil? ) then complete_date = item.elements["complete_date"].text.split('-') completed_at = Time.local(complete_date[0], complete_date[1], complete_date[2]) now = Time.now if (completed_at < now) then archived = TRUE puts "skipping archived item #{item.elements['body'].text}, finished at #{completed_at.to_s} (< #{now.to_s})" end else if (archived == FALSE) then contexts = [] body = item.elements['body'].text item.elements.each("contexts/context") { |context| contexts << context.text } if ( ! item.elements["project/body"].nil? ) then project = item.elements["project/body"].text else project = '' end context_str = "\t" + contexts.join(', ') puts send_task_mail(body, project, context_str, []) #We don't want to a) hammer a server and b) be blacklisted as some spambot. So lets keep it nice and wait between 5 and 11 seconds between each mail. puts sleep(rand + rand(6) + 5) end end }
You need to login to post a comment.
