Created
September 17, 2018 02:11
-
-
Save ak1t0/668f1466f0157cfc45365b1d5496e793 to your computer and use it in GitHub Desktop.
MySQL client and crawler
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
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