Skip to content

Instantly share code, notes, and snippets.

@uu59
Created July 27, 2011 13:13
Show Gist options
  • Save uu59/1109329 to your computer and use it in GitHub Desktop.
Save uu59/1109329 to your computer and use it in GitHub Desktop.
# -- coding: utf-8
=begin
Twitter trend plugin for earthquake.gem
⚡ :trend
trend of Japan
及川光博
#アメリカ版東方projectにありがちなこと
年齢にテンション
金麦のcm
ワージッ
幸村vs
#眼鏡ユーザーあるある
モテ仕草
共演がきっかけ
#up_bl_fes
⚡ :trend london
trend of London
#thingswelearnedontwitter
ITV Player
#1yeartogo
#olympic
Canford Cliffs
London Olympics
Aquatics Centre
Kenan Kel
Ofgem
Olympic Games
=end
require "rubygems"
require "nokogiri"
Earthquake.init do
_ = config[:trend] ||= {}
_[:woeid] ||= 23424856 # japan http://sigizmund.info/woeidinfo/?woeid=japan
process = proc do |woeid|
url = "http://api.twitter.com/1/trends/#{woeid}.json"
res = Net::HTTP.get(URI.parse(url))
json = JSON.parse(res)
if json.class != Array && json["error"]
puts json["error"]
else
puts "trend of #{json.first["locations"].first["name"]}".c(36)
json.first["trends"].each{|t|
puts "#{t["name"]} " if t["name"]
}
end
end
command :trend do
process.call(_[:woeid])
end
command :trend do |m|
woeid = m[1].strip
unless woeid.match(/\A[0-9]+\Z/)
url = "http://sigizmund.info/woeidinfo/?woeid=#{URI.escape(woeid)}"
res = Net::HTTP.get(URI.parse(url))
doc = Nokogiri::HTML.parse(res)
woeid = doc.at('h3').next_sibling.text.match(/[0-9]+/).to_a.first || _[:woeid]
end
process.call(woeid)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment