Skip to content

Instantly share code, notes, and snippets.

@svandragt
Created January 25, 2022 16:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save svandragt/408f5fb4ff01a25a508e23757667052d to your computer and use it in GitHub Desktop.
Save svandragt/408f5fb4ff01a25a508e23757667052d to your computer and use it in GitHub Desktop.
Combine items from multiple feeds
gem "byebug", "~> 11.1", :groups => [:development, :test]
gem "rss", "~> 0.2.9"
#!/usr/bin/env ruby
require "rss"
require "byebug"
require "open-uri"
all = []
urls = [
"https://www.ruby-lang.org/en/feeds/news.rss",
"https://amasan.co.uk/feed-digest/feed/",
].each do |url|
URI.open(url) do |rss|
feed = nil
# parse even invalid feeds, where possible
begin
feed = RSS::Parser.parse rss, validate: false
rescue RSS::InvalidRSSError => e
end
if feed
puts "Title: #{feed.channel.title}"
all += feed.items if feed.items.any?
end
end
end
# todo only items published within the last 24 hrs
all.sort_by! { |item| -item.pubDate.to_i }
all.first(10).each do |item|
puts " - #{item.title} (#{item.pubDate})"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment