Skip to content

Instantly share code, notes, and snippets.

@siyo
Forked from morygonzalez/favstar.rb
Last active October 11, 2015 13:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save siyo/3864884 to your computer and use it in GitHub Desktop.
Save siyo/3864884 to your computer and use it in GitHub Desktop.
favstar ふぁぼったりRTしたユーザ名も見るやつ(色つき + 発見) / earthquakge.gem plugin
# -*- coding: utf-8 -*-
# favstar / earthquakge.gem plugin
#
# option:
# -d : discovered
#
# e.g. :favstar #=> your favstar
# :favstar who #=> who's favstar
# :favstar -d #=> your discovered favstar
# :favstar -d who #=> who's dicovered favstar
#
require 'open-uri'
require 'nokogiri'
Earthquake.once do
class Favstar
attr_reader :tweets
def initialize(user, discovered=false)
@@table ||= {}
key = discovered ? user + "_discovered" : user
@@table[key] ||= {}
@tweets = @@table[key]
@url = "http://favstar.fm/users/#{user}/" + (discovered ? "discovered" : "recent")
end
def update
html = Nokogiri::HTML(open(@url))
html.css("#fs-feed-list > li").each{|st|
id = st.at(".fs-about-tweet a.fs-date").attribute("href").text.sub(/^[^\d]+/, '').to_i
if @tweets.include? id
tw = @tweets[id]
else
tw = {}
tw[:author] = st.at(".fs-author-avatar a.fs-avatar img").attribute("alt").text
tw[:text] = st.at(".fs-tweet-text").text
end
tw[:fav_users] = st.css(".fs-favs a.fs-avatar").map{|a|
a.attribute("title").text
}
tw[:rt_users] = st.css(".fs-retweets a.fs-avatar").map{|a|
a.attribute("title").text
}
@tweets[id] = tw
}
@tweets
end
end
Favstar.new(twitter.info["screen_name"]).update
end
Earthquake.init do
command %r|^:favstar\s*(-d)*\s*(.+)*|, :as => :favstar do |m|
tweets = Favstar.new(m[2] || twitter.info["screen_name"], m[1]).update
mark_color = config[:colors].sample + 10
tweets.sort.each{|id,tw|
var = id2var(id)
puts [ ' '.c(mark_color),
"[#{var}] ".c(:info),
"#{tw[:author].c(color_of(tw[:author]))}: ",
tw[:text],
tw[:fav_users].empty? ? "" : " #{tw[:fav_users].size.to_s.c(:notice)} favs",
tw[:rt_users].empty? ? "" : " #{tw[:rt_users].size.to_s.c(:notice)} RTs",
tw[:fav_users].empty? ? "" : " Faved by ".c(:info),
tw[:fav_users].map{|u|
u.c(color_of(u))
}.join(' '),
tw[:rt_users].empty? ? "" : " RT by ".c(:info),
tw[:rt_users].map{|u|
u.c(color_of(u))
}.join(' ')
].join
}
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment