From 61f0903c195a916f1e03b3980c541635a7cd2577 Mon Sep 17 00:00:00 2001 From: Hexaitos Date: Sun, 10 Nov 2024 15:44:34 +0100 Subject: [PATCH] Remove categories that were causing issues --- categories.txt | 5 ----- get_images_by_category.rb | 2 ++ get_random_image.rb | 23 ++++++++++++++--------- 3 files changed, 16 insertions(+), 14 deletions(-) diff --git a/categories.txt b/categories.txt index 45e4bd3..3397dd4 100644 --- a/categories.txt +++ b/categories.txt @@ -26,16 +26,11 @@ 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 diff --git a/get_images_by_category.rb b/get_images_by_category.rb index 4e808a9..de039f5 100644 --- a/get_images_by_category.rb +++ b/get_images_by_category.rb @@ -6,6 +6,8 @@ def get_images_by_category(categories) random_category = random_category.gsub("Category:", "") end + puts random_category + 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 c647598..e085db6 100644 --- a/get_random_image.rb +++ b/get_random_image.rb @@ -18,15 +18,20 @@ def get_random_image(photos) req.params = params end - 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'] - thumb = info['imageinfo'].first['thumburl'] + begin + 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'] + thumb = info['imageinfo'].first['thumburl'] + rescue + puts "ERROR OCCURRED" + return {:user => user, :url => url, :thumb => thumb, :license => license, :desc => desc, :license_url => license_url, :user_url => user_url} + end return {:user => user, :url => url, :thumb => thumb, :license => license, :desc => desc, :license_url => license_url, :user_url => user_url} end \ No newline at end of file