Skip to content

Instantly share code, notes, and snippets.

@YuukiToriyama
Created October 17, 2019 21:23
Show Gist options
  • Save YuukiToriyama/81bedb4683c1abdaf69da3b2ada8e27b to your computer and use it in GitHub Desktop.
Save YuukiToriyama/81bedb4683c1abdaf69da3b2ada8e27b to your computer and use it in GitHub Desktop.
flickrから条件に合う写真を取ってくるスクリプト
#!/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