Skip to content

Instantly share code, notes, and snippets.

@meeech
Created November 18, 2010 22:34
Show Gist options
  • Save meeech/705801 to your computer and use it in GitHub Desktop.
Save meeech/705801 to your computer and use it in GitHub Desktop.
download and save the index.html
#!/usr/bin/env ruby
require 'net/http'
require 'uri'
require 'rubygems'
require 'json'
require 'config.rb'
# puts URI.escape($posterous_auth_email)
theme_url = "http://posterous.com/api/2/users/#{$posterous_user_id}/sites/#{$posterous_site_id}/theme?api_token=#{$posterous_api_token}"
# puts theme_url
url = URI.parse(theme_url)
req = Net::HTTP::Get.new(url.path + '?'+ url.query)
req.basic_auth $posterous_auth_email, $posterous_auth_pw
res = Net::HTTP.start(url.host, url.port) {|http|
http.request(req)
}
result = res.body
parser = JSON.parse(result)
#JSON.Parser.new(result)
parser.each do |key, value|
begin
puts 'writing...'
handle = File.open('index.html', 'w') if key == 'raw_theme'
handle.write(value)
rescue Exception => e
puts 'error: '
puts e
end if key == 'raw_theme'
end
# puts parser
#
# puts res.error!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment