Skip to content

Instantly share code, notes, and snippets.

@collindonnell
Last active May 4, 2021 20:52
Show Gist options
  • Save collindonnell/16fd17a701686f9d67de075a03839c7c to your computer and use it in GitHub Desktop.
Save collindonnell/16fd17a701686f9d67de075a03839c7c to your computer and use it in GitHub Desktop.
Hey World Posts Counter
#!/usr/bin/env ruby
require 'rss'
require 'open-uri'
class Blog
def initialize(name)
@name = name
end
def feed_url
"https://world.hey.com/#{@name}/feed.atom"
end
def fetch_posts
URI.open(feed_url) do |rss|
begin
feed = RSS::Parser.parse(rss)
feed.items.each do |item|
date=item.published.content
yield date.to_s[/2021-\d\d-\d\d/]
end
rescue => error
STDERR.puts "Error parsing #{feed_url}"
STDERR.puts "#{error}"
next
end
end
end
end
posts_per_day = Hash.new
i = 0
File.read("blog_list").split.sort.each do |name|
blog = Blog.new name
blog.fetch_posts do |date|
if not posts_per_day[date]
posts_per_day[date] = 1
else
STDERR.print "."
posts_per_day[date] = posts_per_day[date] + 1
end
i = i + 1
end
end
posts_per_day.each do |key, value|
puts "#{key},#{value}"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment