Hey World Posts Counter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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