Created
June 11, 2012 16:55
-
-
Save soramugi/2911232 to your computer and use it in GitHub Desktop.
おっぱい
This file contains 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
# -*- coding: utf-8 -*- | |
require "pit" | |
require "addressable/uri" | |
require "open-uri" | |
require "xmlsimple" | |
require "digest/md5" | |
require 'pathname' | |
# http://yusukebe.com/archives/20120520/164309.html | |
config = Pit.get("yahoo_search", :require => { | |
"app_id" => "yahoo app id" | |
}) | |
dir = Pathname.new('./oppaidata') | |
count = 1 | |
page = 1 | |
loop do | |
uri = Addressable::URI.parse("http://search.yahooapis.jp/ImageSearchService/V2/imageSearch") | |
uri.query_values = { | |
:appid => config['app_id'], | |
:query => 'おっぱい', | |
:results => 20, | |
:adult_ok => 1, | |
:format => 'jpeg', | |
:site => 'tumblr.com', | |
:start => (page - 1) * 20 + 1 | |
} | |
res = open(uri) rescue retry | |
xml = res.read | |
data = XmlSimple.xml_in(xml) | |
break unless data["Result"] | |
data["Result"].each do |item| | |
url = item["Url"][0] | |
filename = Digest::MD5.hexdigest(url) + '.jpg' | |
filepath = dir + filename | |
puts "#{count} : Download #{url} ..." | |
res = open(url) rescue next | |
open(filepath,'w').print res.read | |
count += 1 | |
end | |
if count > 100 then | |
break | |
end | |
page += 1 | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment