Skip to content

Instantly share code, notes, and snippets.

@coneybeare
Created August 28, 2009 02:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save coneybeare/176748 to your computer and use it in GitHub Desktop.
Save coneybeare/176748 to your computer and use it in GitHub Desktop.
require 'net/http'
require 'uri'
require 'cgi'
require "mysql"
db = Mysql.real_connect("<MYSQL SERVER>", "<MYSQL USER>", "<MYSQL PASSWORD>", "<MYSQL TABLE>")
rows = db.query("SELECT * FROM posts")
while (row = rows.fetch_row)
title = row[4]
body = row[6]
date = row[2]
url = URI.parse('http://posterous.com/api/newpost')
req = Net::HTTP::Post.new(url.path)
req.basic_auth '<POSTEROUSEMAIL>', '<POSTEROUSPASSWORD>'
req.set_form_data({'site_id'=>'<POSTEROUS SITE_ID>', 'title'=>title, 'body'=>body, 'date'=>date})
res = Net::HTTP.new(url.host, url.port).start {|http| http.request(req) }
case res
when Net::HTTPSuccess, Net::HTTPRedirection
puts res.body
puts '-----------------------------------------------------------------------'
else
res.error!
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment