Add more categories, fix category parsing, link to user and license
This commit is contained in:
parent
dac566f2c8
commit
77042d1c1e
|
@ -9,3 +9,37 @@ https://commons.wikimedia.org/wiki/Category:Quality_images_of_Falco_rusticolus
|
||||||
https://commons.wikimedia.org/wiki/Category:Quality_images_of_Falco_sparverius
|
https://commons.wikimedia.org/wiki/Category:Quality_images_of_Falco_sparverius
|
||||||
https://commons.wikimedia.org/wiki/Category:Quality_images_of_Falco_tinnunculus
|
https://commons.wikimedia.org/wiki/Category:Quality_images_of_Falco_tinnunculus
|
||||||
https://commons.wikimedia.org/wiki/Category:Quality_images_of_Falco_vespertinus
|
https://commons.wikimedia.org/wiki/Category:Quality_images_of_Falco_vespertinus
|
||||||
|
https://commons.wikimedia.org/wiki/Category:Quality_images_of_Caracara_plancus
|
||||||
|
Category:Quality_images_of_Accipiter_badius
|
||||||
|
Category:Quality_images_of_Accipiter_cooperii
|
||||||
|
Category:Quality_images_of_Accipiter_minullus
|
||||||
|
Category:Quality_images_of_Accipiter_nisus
|
||||||
|
Category:Quality images of Aquila audax
|
||||||
|
Category:Quality images of Aquila chrysaetos
|
||||||
|
Category:Quality images of captive Aquila heliaca
|
||||||
|
Category:Quality images of captive Aquila nipalensis
|
||||||
|
Category:Quality images of Aquila spilogaster
|
||||||
|
Category:Quality images of Buteo augur
|
||||||
|
Category:Quality images of Buteo buteo
|
||||||
|
Category:Quality images of Buteo galapagoensis
|
||||||
|
Category:Quality images of Buteo jamaicensis
|
||||||
|
Category:Quality images of Buteo lineatus
|
||||||
|
Category:Quality images of Buteo regalis
|
||||||
|
Category:Quality images of Buteogallus
|
||||||
|
Category:Quality images of Aquila
|
||||||
|
Category:Quality images of Buteo
|
||||||
|
Category:Quality images of Circaetus
|
||||||
|
Category:Quality images of Circaetus gallicus
|
||||||
|
Category:Quality images of Circaetus pectoralis
|
||||||
|
Category:Quality_images_of_Circus
|
||||||
|
Category:Quality images of Circus aeruginosus
|
||||||
|
Category:Quality images of Circus cyaneus
|
||||||
|
Category:Quality images of Circus hudsonius
|
||||||
|
Category:Quality_images_of_Haliaeetus
|
||||||
|
Category:Quality images of Haliaeetus albicilla
|
||||||
|
Category:Quality images of Haliaeetus leucocephalus
|
||||||
|
Category:Quality images of Haliaeetus leucogaster
|
||||||
|
Category:Quality images of captive Haliaeetus pelagicus
|
||||||
|
Category:Quality images of Haliaeetus vocifer
|
||||||
|
Category:Quality images of Haliastur indus
|
||||||
|
Category:Quality images of Haliastur sphenurus
|
|
@ -1,5 +1,11 @@
|
||||||
def get_images_by_category(categories)
|
def get_images_by_category(categories)
|
||||||
random_category = categories.sample.gsub("https://commons.wikimedia.org/wiki/Category:", "")
|
random_category = categories.sample
|
||||||
|
if random_category.include?("https://commons.wikimedia.org/wiki/Category:") then
|
||||||
|
random_category = random_category.gsub("https://commons.wikimedia.org/wiki/Category:", "")
|
||||||
|
elsif random_category.include?("Category:") then
|
||||||
|
random_category = random_category.gsub("Category:", "")
|
||||||
|
end
|
||||||
|
|
||||||
photos = []
|
photos = []
|
||||||
|
|
||||||
conn = Faraday.new(url: 'https://commons.wikimedia.org/w/api.php') do |faraday|
|
conn = Faraday.new(url: 'https://commons.wikimedia.org/w/api.php') do |faraday|
|
||||||
|
|
|
@ -20,9 +20,11 @@ def get_random_image(photos)
|
||||||
data = JSON.parse(response.body)
|
data = JSON.parse(response.body)
|
||||||
info = data['query']['pages'].values.first
|
info = data['query']['pages'].values.first
|
||||||
user = info['imageinfo'].first['user']
|
user = info['imageinfo'].first['user']
|
||||||
|
user_url = info['imageinfo'].first['extmetadata']['Artist']['value']
|
||||||
url = info['imageinfo'].first['url']
|
url = info['imageinfo'].first['url']
|
||||||
license = info['imageinfo'].first['extmetadata']['LicenseShortName']['value']
|
license = info['imageinfo'].first['extmetadata']['LicenseShortName']['value']
|
||||||
|
license_url = info['imageinfo'].first['extmetadata']['LicenseUrl']['value']
|
||||||
desc = info['imageinfo'].first['extmetadata']['ImageDescription']['value']
|
desc = info['imageinfo'].first['extmetadata']['ImageDescription']['value']
|
||||||
|
|
||||||
return {:user => user, :url => url, :license => license, :desc => desc}
|
return {:user => user, :url => url, :license => license, :desc => desc, :license_url => license_url, :user_url => user_url}
|
||||||
end
|
end
|
|
@ -3,6 +3,6 @@
|
||||||
<img class="refsheet" src="<%= image[:url] %>">
|
<img class="refsheet" src="<%= image[:url] %>">
|
||||||
</a>
|
</a>
|
||||||
<p><strong>Description:</strong> <%= image[:desc] %></p>
|
<p><strong>Description:</strong> <%= image[:desc] %></p>
|
||||||
<p><strong>Photo by:</strong> <%= image[:user] %></p>
|
<p><strong>Photo by:</strong> <%= image[:user_url] %></p>
|
||||||
<p><strong>Licensed under:</strong> <%= image[:license] %></p>
|
<p><strong>Licensed under:</strong> <a href="<%= image[:license_url] %>"><%= image[:license] %></a></p>
|
||||||
<p><strong>URL:</strong> <a href="<%= image[:url] %>" target="_blank"><%= image[:url] %></a></p>
|
<p><strong>URL:</strong> <a href="<%= image[:url] %>" target="_blank"><%= image[:url] %></a></p>
|
Loading…
Reference in New Issue