Skip to content

Instantly share code, notes, and snippets.

@joshtronic
Created January 30, 2012 00:09
Show Gist options
  • Save joshtronic/1701489 to your computer and use it in GitHub Desktop.
Save joshtronic/1701489 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
require 'rubygems'
require 'hpricot'
begin
# Reads in source created by viewing source on teuxdeux.com and saving it
# Use Firefox, as the Chrome view source mucks up the source
file = File.new('list.html', 'r');
# Converts the HTML into an object
html = Hpricot(file)
# Pulls out the undone list items
list_items = (html/'li[@class="todo_item"]');
list_items.each do |list_item|
# This pulls the todo list item
todo_item = (list_item/'p.teuxdeux').innerHTML
# The following is code to generate queries to import teuxdeux.com data
# to the wonderous http://todoapp.plan8home.com but could be altered to
# support a migration to any other service
# Creates a time object to set the created value
time = Time.new
# Swap me out with your user ID
user_id = '%UID%'
# Displays the SQL to migrate the record
puts 'INSERT INTO todoapp.todos (user_id, name, eventually, created) VALUES ("' + user_id + '", "' + todo_item + '", 1, "' + time.strftime("%Y-%m-%d %H:%M:%S") + '");'
end
rescue Exception => e
print e, "\n"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment