Created
September 7, 2009 17:44
-
-
Save epall/182479 to your computer and use it in GitHub Desktop.
lastblog.rb: a simple script for checking how recently I've posted to my blogs. Edit the BLOGS and MAX_ENTRY_INTERVAL globals to suit your tastes. term/ansicolor is an optional gem that will make the output prettier.
This file contains hidden or 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 | |
# lastblog: a simple script for checking how recently I've posted to my blogs. | |
# Edit the BLOGS and MAX_ENTRY_INTERVAL globals to suit your tastes. | |
# term/ansicolor is an optional gem that will make the output prettier. | |
require 'rss/1.0' | |
require 'rss/2.0' | |
require 'open-uri' | |
require 'date' | |
BLOGS = { | |
"Personal" => 'http://svallens.com/eric/rss', | |
"Eric on Tracks" => 'http://svallens.com/ericontracks/rss', | |
"Hacker|Engineer" => 'http://hackerengineer.net/rss' | |
} | |
MAX_ENTRY_INTERVAL = 8.0 | |
begin | |
require 'rubygems' | |
require 'term/ansicolor' | |
include Term::ANSIColor | |
rescue LoadError | |
end | |
def print_entry(name, publish_date) | |
days = Date.today - publish_date | |
print sprintf("%-16s", name), ": ", publish_date, " -- " | |
if defined?(Term) | |
include Term::ANSIColor | |
if days >= MAX_ENTRY_INTERVAL | |
print on_red(black(days.to_s + " days old")) | |
elsif days >= MAX_ENTRY_INTERVAL*0.75 | |
print on_yellow(black(days.to_s + " days old")) | |
else | |
print on_green(black(days.to_s + " days old")) | |
end | |
else | |
print days, " days old" | |
end | |
print "\n" | |
end | |
BLOGS.each do |name, url| | |
content = "" # raw content of rss feed will be loaded here | |
open(url) do |s| content = s.read end | |
rss = RSS::Parser.parse(content, false) | |
publish_time = rss.items[0].date | |
publish_date = Date.civil(publish_time.year, publish_time.month, publish_time.day) | |
print_entry(name, publish_date) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment