Created
September 15, 2016 02:11
-
-
Save littlekbt/3cb646c61e653e619cc3244889ca50e1 to your computer and use it in GitHub Desktop.
This file contains 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
require './oauth_cli' | |
require 'redis' | |
oauth_cli = OauthCli.new( | |
consumer_key: 'consumer_key', | |
consumer_secret: 'consumer_secret', | |
oauth_token: 'oauth_token', | |
oauth_token_secret: 'oauth_token_secret', | |
host: 'http://f.hatena.ne.jp', | |
) | |
redis = Redis.new | |
Dir.glob("/home/vagrant/src/blog/move/dl_images/images/**/*.*").each do |img| | |
m = img.match(/.*\/(.*)\/(.*\.*)/) | |
d = m[1] | |
i = m[2] | |
body =<<EOF | |
<entry xmlns="http://purl.org/atom/ns#"> | |
<title>img-#{i}</title> | |
<content mode="base64" type="image/jpeg">#{Base64.encode64(File.open("/home/vagrant/src/blog/move/dl_images/images/#{d}/#{i}").read).chop}</content> | |
</entry> | |
EOF | |
begin | |
res = oauth_cli.upload_image('/atom/post', body) | |
unless res.body['entry']['imageurl'] | |
fail Exception unless res.body['entry']['imageurl'] | |
end | |
redis.set("#{d}/#{i}", res.body['entry']['imageurl']) | |
p "#{d}/#{i} -> #{res.body['entry']['imageurl']}" | |
rescue => e | |
p res | |
p e | |
p "Error!!!! #{d}/#{i}" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment