Created
November 18, 2010 22:34
-
-
Save meeech/705801 to your computer and use it in GitHub Desktop.
download and save the index.html
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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