Skip to content

Instantly share code, notes, and snippets.

@ak1t0
Created September 17, 2018 02:11
Show Gist options
  • Save ak1t0/668f1466f0157cfc45365b1d5496e793 to your computer and use it in GitHub Desktop.
Save ak1t0/668f1466f0157cfc45365b1d5496e793 to your computer and use it in GitHub Desktop.
MySQL client and crawler
require 'mysql2'
require 'net/http'
images = []
client = Mysql2::Client.new(:host => "localhost", :password => "isucon", :username => "isucon", :database => "isubata")
client.query("SELECT name FROM image").each do |col1|
images.push(col1["name"])
end
images = images.uniq
p images.size
images.each do |image|
p "http:/localhost/icons/" + image
p Net::HTTP.get_response(URI.parse("http://localhost/icons/" + image)).code
open("icons/#{image}", 'wb') do |file|
file.write(Net::HTTP.get_response(URI.parse("http://localhost/icons/" + image)).body)
end
sleep(0.1)
end
p "done"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment