Skip to content

Instantly share code, notes, and snippets.

@morygonzalez
Forked from siyo/favstar.rb
Created September 13, 2012 09:03
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 morygonzalez/3713069 to your computer and use it in GitHub Desktop.
Save morygonzalez/3713069 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 '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}/recent"
html = Nokogiri::HTML(open(url))
html.css("#fs-feed-list > li").reverse.each{|st|
status_id = st.at(".fs-about-tweet a.fs-date").attribute("href").text.sub(/^[^\d]+/,'')
tweet = st.at(".fs-tweet-text").text
favs = st.css(".fs-favs a.fs-avatar").map{|a|
fav_user = a.attribute("title").text
"#{fav_user} ".c(color_of(fav_user))
}
favs_size = st.at(".fs-favs li.fs-total").text rescue nil
rts = st.css(".fs-retweets a.fs-avatar").map{|a|
rt_user = a.attribute("title").text
"#{rt_user} ".c(color_of(rt_user))
}
rts_size = st.at(".fs-retweets li.fs-total").text rescue nil
puts "%s%s %s %s %s %s %s%s" % [
' '.c(mark_color),
"[#{id2var(status_id.to_i)}]".c(:info),
"#{user.c(color_of(user))}:",
tweet,
favs.empty? ? "" : "#{favs_size.c(:notice)} favs",
rts.empty? ? "" : "#{rts_size.c(:notice)} RTs",
favs.empty? ? "" : "Faved by ".c(:info) + favs.join(' '),
rts.empty? ? "" : "RT by ".c(:info) + rts.join(' ')
]
}
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment