diff --git a/categories.txt b/categories.txt index 4304492..45e4bd3 100644 --- a/categories.txt +++ b/categories.txt @@ -8,4 +8,38 @@ https://commons.wikimedia.org/wiki/Category:Quality_images_of_Falco_naumanni 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_tinnunculus -https://commons.wikimedia.org/wiki/Category:Quality_images_of_Falco_vespertinus \ No newline at end of file +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 \ No newline at end of file diff --git a/get_images_by_category.rb b/get_images_by_category.rb index 980c366..4e808a9 100644 --- a/get_images_by_category.rb +++ b/get_images_by_category.rb @@ -1,5 +1,11 @@ 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 = [] conn = Faraday.new(url: 'https://commons.wikimedia.org/w/api.php') do |faraday| diff --git a/get_random_image.rb b/get_random_image.rb index ae2d202..8681c8e 100644 --- a/get_random_image.rb +++ b/get_random_image.rb @@ -20,9 +20,11 @@ def get_random_image(photos) data = JSON.parse(response.body) info = data['query']['pages'].values.first user = info['imageinfo'].first['user'] + user_url = info['imageinfo'].first['extmetadata']['Artist']['value'] url = info['imageinfo'].first['url'] license = info['imageinfo'].first['extmetadata']['LicenseShortName']['value'] + license_url = info['imageinfo'].first['extmetadata']['LicenseUrl']['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 \ No newline at end of file diff --git a/views/index.erb b/views/index.erb index 7854ede..92403e6 100644 --- a/views/index.erb +++ b/views/index.erb @@ -3,6 +3,6 @@

Description: <%= image[:desc] %>

-

Photo by: <%= image[:user] %>

-

Licensed under: <%= image[:license] %>

+

Photo by: <%= image[:user_url] %>

+

Licensed under: <%= image[:license] %>

URL: <%= image[:url] %>

\ No newline at end of file