Skip to content

Instantly share code, notes, and snippets.

@morygonzalez
Forked from siyo/favstar.rb
Created November 28, 2011 14:41
Show Gist options
  • Save morygonzalez/1400635 to your computer and use it in GitHub Desktop.
Save morygonzalez/1400635 to your computer and use it in GitHub Desktop.
favstar 見るやつ(色つき) / earthquakge.gem plugin
# -*- coding: utf-8 -*-
# favstar / earthquakge.gem plugin
#
# e.g. :favstar #=> your favstar
# :favstar who #=> who's favstar
#
require 'rss'
Earthquake.init do
command %r|^:favstar\s*(.+)*|, :as => :favstar do |m|
user = m[1] || twitter.info["screen_name"]
mark_color = config[:colors].sample + 10
url = "http://favstar.fm/users/#{user}/rss"
feed = RSS::Parser.parse(open(url){|f| f.read}, false)
feed.items.reverse.each{|item|
status_id = item.link.gsub(/^.+\/([\d]+?)$/, "\\1")
star,text = item.title.scan(/^(\d+)\s+stars?:\s(.+)$/).flatten
pub_date = item.pubDate.strftime("%d %B %H:%M").c(:info)
mark = ' '.c(mark_color)
display_name = "#{user.c(color_of(user))}:"
star_info = "#{star.c(:notice)} #{star.to_i < 2 ? 'fav' : 'favs'}"
status_var = "[#{id2var(status_id.to_i)}]".c(:info)
puts "%s%s %s %s %s %s" % [mark, status_var, display_name, text, star_info, pub_date]
}
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment