Created
October 17, 2019 21:23
-
-
Save YuukiToriyama/81bedb4683c1abdaf69da3b2ada8e27b to your computer and use it in GitHub Desktop.
flickrから条件に合う写真を取ってくるスクリプト
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
#!/usr/bin/env ruby | |
require 'open-uri' | |
require 'json' | |
query_table = [ | |
["api_key", ""], # https://www.flickr.com/services/appsでアプリを作成しapiキーを入手してください | |
["method", "flickr.photos.search"], | |
["tags", "soviet,russia"], # タグをコンマ区切りで指定します | |
["tag_mode", "all"], # anyを指定すると「または」、allを指定すると「かつ」 | |
["min_taken_date", "2019/08/31"], | |
["max_taken_date", ""], | |
["has_geo", 1], # 1を指定するとジオタグのついた写真だけが検索されます。 | |
["extras", "geo,url_h,url_sq,date_taken,owner_name,description"], | |
["format", "json"], # 何も指定しないとxml形式で結果が返ってきます | |
["nojsoncallback", 1] | |
].to_h | |
uri = URI.parse("https://api.flickr.com/services/rest") | |
uri.query = URI.encode_www_form(query_table) | |
file = URI.open(uri.to_s).read | |
JSON.parse(file)["photos"]["photo"].each do |elm| | |
puts elm["url_h"] | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment