Created
September 5, 2014 02:02
-
-
Save labocho/b9cdf72e54439fccaaab to your computer and use it in GitHub Desktop.
引数で指定したユーザの twitpic のメタデータと画像を ./twitpic に保存
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 | |
| gem "rest-client", "~> 1.6.6" | |
| require "rest-client" | |
| require "json" | |
| require "time" | |
| unless username = ARGV.first | |
| STDERR.puts "Usage: backup-twitpic username" | |
| exit 1 | |
| end | |
| Dir.mkdir("twitpic") unless Dir.exists?("twitpic") | |
| Dir.chdir("twitpic") do | |
| user_json = RestClient.get("http://api.twitpic.com/2/users/show.json?username=#{username}") | |
| File.write("user.json", user_json) | |
| user = JSON.parse(user_json) | |
| user["images"].each do |i| | |
| timestamp = Time.parse(i["timestamp"]).strftime("%Y%m%d%H%M%S") | |
| message_escaped = i["message"].gsub("/", "_") | |
| filename = "#{timestamp}-#{i["short_id"]}-#{message_escaped}.#{i["type"]}" | |
| url = "http://twitpic.com/show/full/#{i["short_id"]}" | |
| STDERR.puts "Download #{url}" | |
| File.write(filename, RestClient.get(url)) | |
| sleep 1 | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment