Skip to content

Instantly share code, notes, and snippets.

@littlekbt
Created September 15, 2016 02:11
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 littlekbt/3cb646c61e653e619cc3244889ca50e1 to your computer and use it in GitHub Desktop.
Save littlekbt/3cb646c61e653e619cc3244889ca50e1 to your computer and use it in GitHub Desktop.
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