Skip to content

Instantly share code, notes, and snippets.

@josqu4red
Created March 4, 2014 10:27
Show Gist options
  • Save josqu4red/9343917 to your computer and use it in GitHub Desktop.
Save josqu4red/9343917 to your computer and use it in GitHub Desktop.
Parse Atom feeds and display only entries from less than <delta> days ago. Useful for tracking software updates
#!/usr/bin/env ruby
require "rss"
require "yaml"
require "getoptlong"
opts = GetoptLong.new(
[ '--feeds', '-f', GetoptLong::REQUIRED_ARGUMENT ],
[ '--delta', '-d', GetoptLong::REQUIRED_ARGUMENT ],
)
feeds = "feeds.yaml"
delta = 1
opts.each do |opt, arg|
case opt
when '--feeds'
feeds = arg
when '--delta'
delta = arg.to_i
end
end
begin
config = YAML.load_file(File.realpath(feeds))
rescue Exception => e
puts "Unable to load config file: #{e.message}"
exit 1
end
results = Hash.new{|h,k| h[k] = []}
config[:feeds].map do |name, url|
Thread.new do
begin
open(url) do |rss|
feed = RSS::Parser.parse(rss)
feed.entries.each do |entry|
break if entry.updated.content < (Time.now - delta * 86400)
results[name] << "#{entry.updated.content}: #{entry.title.content}. see #{entry.link.href}"
end
end
rescue Exception => e
puts "Failed to retrieve #{name} feed (#{e.message})"
end
end
end.each{|t| t.join}
results.each do |name, content|
puts "## %s\n%s" % [name, content.join("\n")]
end
---
:feeds:
Jenkins: https://github.com/jenkinsci/jenkins/releases.atom
Postgres: https://github.com/postgres/postgres/releases.atom
HAproxy: http://freecode.com/projects/haproxy/releases.atom
Elasticsearch: https://github.com/elasticsearch/elasticsearch/releases.atom
Lita: https://github.com/jimmycuadra/lita/releases.atom
InfluxDB: https://github.com/influxdb/influxdb/releases.atom
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment