Skip to content

Commit

Permalink
Bugfix: fetching Wikipedia URL from Wikidata was not using redirects …
Browse files Browse the repository at this point in the history
…correctly (#3838)
  • Loading branch information
kueda committed Aug 14, 2023
1 parent 353663a commit 3391162
Showing 1 changed file with 2 additions and 7 deletions.
9 changes: 2 additions & 7 deletions lib/taxon_describers/lib/taxon_describers/wikipedia.rb
Expand Up @@ -107,26 +107,21 @@ def content_for_title( title )
def wikidata_wikipedia_url_for_taxon( taxon )
lang = @locale.to_s.split( "-" ).first
Rails.cache.fetch( "wikidata_wikipedia_url_for_taxon-#{taxon.id}-#{lang}", expires_in: 1.day ) do
Timeout::timeout( 5 ) do
if r = fetch_head( "https://hub.toolforge.org/P3151:#{taxon.id}?lang=#{lang}" )
Timeout.timeout( 5 ) do
if ( r = fetch_head( "https://hub.toolforge.org/P3151:#{taxon.id}?lang=#{lang}", follow_redirects: false ) )
if r.header[:location].blank?
nil
else
uri = URI.parse( r.header[:location].to_s ) rescue nil
if uri && uri.host.split( "." )[0] == lang
r.header[:location]
else
nil
end
end
else
nil
end
rescue Timeout::Error
nil
end
end
end
end

end

0 comments on commit 3391162

Please sign in to comment.