Skip to content

Instantly share code, notes, and snippets.

@hecomi
Forked from siyo/favstar.rb
Created April 4, 2012 15:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save hecomi/2303185 to your computer and use it in GitHub Desktop.
Save hecomi/2303185 to your computer and use it in GitHub Desktop.
favstar ふぁぼったりRTしたユーザ名も見るやつ(色つき) / earthquakge.gem plugin
# -*- coding: utf-8 -*-
# favstar / earthquakge.gem plugin
#
# e.g. :favstar #=> your favstar
# :favstar who #=> who's favstar
#
require 'rss'
require 'open-uri'
require 'nokogiri'
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.gsub(/\r?\n/," ").scan(/^(\d+)\s+stars?:\s(.+)$/).flatten
pub_date = item.pubDate.strftime("%d %B %H:%M")
html = Nokogiri::HTML(open(item.link))
favs = ""
rts = ""
html.css("div[id^='faved_by'] a.avatar").each{|a|
fav_user = a.attribute("title").text
favs << "#{fav_user} ".c(color_of(fav_user))
}
html.css("div[id^='rt_by'] a.avatar").each{|a|
rt_user = a.attribute("title").text
rts << "#{rt_user} ".c(color_of(rt_user))
}
puts "%s%s %s %s %s %s %s%s" % [
' '.c(mark_color),
"[#{id2var(status_id.to_i)}]".c(:info),
"#{user.c(color_of(user))}:",
text,
"#{star.c(:notice)} favs",
pub_date.c(:info),
(favs != "") ? "Faved by ".c(:info) + favs : " ",
(rts != "") ? "RT by ".c(:info) + rts : ""
]
}
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment