Created
July 27, 2011 13:13
-
-
Save uu59/1109329 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -- 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