Skip to content

Instantly share code, notes, and snippets.

@svandragt
Created Jan 25, 2022
Embed
What would you like to do?
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