Skip to content

Instantly share code, notes, and snippets.

@jbilbo
Last active August 29, 2015 14:10
Show Gist options
  • Save jbilbo/fcea794c0856a6de7327 to your computer and use it in GitHub Desktop.
Save jbilbo/fcea794c0856a6de7327 to your computer and use it in GitHub Desktop.
Little script to export photos from s3 with specific thumbnail, based on a json
#!/usr/bin/env ruby
require 'json'
base_url = 'project.s3.amazonaws.com'
# Example JSON
#{
#"data":
# [
# {
# "id": 1234,
# "asset_file_name": "95a4fe64c05bc47cec7f668bfe655fd0.png",
# "asset_content_type": "image/png",
# "asset_file_size": 49047,
# "asset_updated_at": "2014-11-10 19:43:51",
# "user_id": 123,
# "original_file_name": "ne001.png"
# },
# ...
# ]
#}
file = File.read('info_photos.json')
data_json = JSON.parse(file)
data_json['data'].each do |p|
system "wget http://#{base_url}/asset_photos/#{p['id']}/android_tiny_mdpi/#{p['asset_file_name']}"
system "mv #{p['asset_file_name']} #{p['original_file_name']}.1"
system "wget http://#{base_url}/asset_photos/#{p['id']}/android_tiny_hdpi/#{p['asset_file_name']}"
system "mv #{p['asset_file_name']} #{p['original_file_name']}.2"
system "wget http://#{base_url}/asset_photos/#{p['id']}/android_mdpi/#{p['asset_file_name']}"
system "mv #{p['asset_file_name']} #{p['original_file_name']}.3"
system "wget http://#{base_url}/asset_photos/#{p['id']}/android_hdpi/#{p['asset_file_name']}"
system "mv #{p['asset_file_name']} #{p['original_file_name']}.4"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment