Created
November 3, 2011 17:14
-
-
Save siyo/1337084 to your computer and use it in GitHub Desktop.
今見てるテレビ番組を呟きたくなったとき用earthquake.gem plugin
This file contains hidden or 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 -*- | |
# watching tv tweet (Tokyo ver.) / earthquake.gem plugin | |
# | |
# e.g. :tv 1 # => update '『松本人志のコント・MHK[再放送]』 を視聴します。' [Yn] | |
# | |
require 'rss' | |
Earthquake.init do | |
once do | |
TV_URL_FORMAT = 'http://twitter.com/statuses/user_timeline/tv_%s.rss' | |
TV_CHANNELS = { | |
1 => 'nhk', | |
2 => 'etv', | |
4 => 'ntv', | |
5 => 'tvasahi', | |
6 => 'tbs', | |
7 => 'tvtokyo', | |
8 => 'fujitv', | |
} | |
end | |
command %r|^:tv\s*(\d+)$|, :as => :tv do |m| | |
ch = m[1].to_i | |
tv = TV_CHANNELS.keys.include?(ch) ? TV_CHANNELS[ch] : nil | |
if tv | |
tweet = RSS::Parser.parse(open(TV_URL_FORMAT % [tv]){|f| f.read},false).items[0].description | |
program = tweet.scan(/「.+」/)[0].gsub("「","『").gsub("」","』") | |
input("%s を視聴します" % [program]) | |
else | |
puts "invalid channel: " + m[1] | |
end | |
end | |
command :tv_onair do | |
tv = TV_CHANNELS.each{|k,v| | |
tweet = RSS::Parser.parse(open(TV_URL_FORMAT % v){|f| f.read},false).items[0].description | |
program = tweet.scan(/「.+」/)[0] | |
puts "%d: %s" % [k, program] | |
} | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment