Fetch your posterous theme. my first rb script.
#!/usr/bin/env ruby | |
# script that goes and fetches your posterous.com theme file. | |
require 'net/http' | |
require 'uri' | |
require 'rubygems' | |
require 'json' | |
# config.rb should contain all the global vars found in this script. | |
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment