Skip to content

Instantly share code, notes, and snippets.

@JamesPrudente
Created February 4, 2012 20:14
Show Gist options
  • Save JamesPrudente/1739847 to your computer and use it in GitHub Desktop.
Save JamesPrudente/1739847 to your computer and use it in GitHub Desktop.
dashwire image extractor
#!/usr/bin/env ruby
require 'rubygems'
require 'work_queue'
require 'json'
require 'faraday'
require 'open-uri'
def download_image( uri, name )
File.open( name, 'wb' ) do | file |
file.write( open( uri ).read )
end
rescue Exception => e
puts e
end
connection = Faraday.new(:url => 'https://dashwire.com')
response = connection.post 'sessions', { 'user[login]'=> ARGV[ 0 ], 'user[password]'=> ARGV[ 1 ] }
set_cookies = CGI::Cookie::parse( response.headers[ 'set-cookie' ] )
puts set_cookies
session_id = set_cookies[ '_session_id' ].first
puts session_id
user_json = connection.get 'http://dashwire.com/users/0.json', {'Cookie'=>"_session_id=#{ session_id }"}
user = JSON.parse( user_json.body )
photo_url = user[ 'photo_url' ]
user_guid = photo_url.split( '/' )[ 4 ]
images_json = connection.get 'http://dashwire.com/images.json', {'Cookie'=>"_session_id=#{ session_id }"}
# images = connection.get '/images.json'
# puts images.body
images = JSON.parse( images_json.body )
work_queue = WorkQueue.new( 10 )
image_urls = images.map do | image |
uri = "http://#{ image['bucket'] }/media/#{ user_guid }/#{ image['guid']}.jpg"
filename = image['guid'] + ".jpg"
# work_queue.enqueue_b {
download_image( uri, filename )
# }
end
puts image_urls
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment