Skip to content

Commit

Permalink
Update cached link handling
Browse files Browse the repository at this point in the history
- Check if there are any cached links on SerpApi Response
- Recreate cached links if there aren't any cached links
  • Loading branch information
kagermanov27 committed Mar 19, 2024
1 parent 3fe09ed commit 3eea0c0
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion lib/clauneck.rb
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,13 @@ def parse_pages(pages)
if !pages.empty? && pages != nil
pages.flat_map do |page|
if page
page['organic_results']&.map { |r| r.dig('cached_page_link') }
cached_links = page['organic_results']&.map { |r| r.dig('cached_page_link') }
direct_links = page['organic_results']&.map { |r| r.dig('link') }
if !cached_links&.compact.empty?
cached_links
else
direct_links&.map {|r| "http://webcache.googleusercontent.com/search?q=cache:#{r}"}
end
else
puts <<-HELP
Warning: There's a problem connecting to SerpApi. Make sure you have used the correct API Key.
Expand Down

0 comments on commit 3eea0c0

Please sign in to comment.