Skip to content

Instantly share code, notes, and snippets.

@moguno
Last active September 8, 2015 12:15
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save moguno/f2e10c805d93faff9b07 to your computer and use it in GitHub Desktop.
Save moguno/f2e10c805d93faff9b07 to your computer and use it in GitHub Desktop.
みくったーたいふーん ー気象庁のAPIを使って最新の台風18号情報をお伝えしますー
#coding: UTF-8
require "net/http"
require "json"
chaban = File.join(CHIConfig::PLUGIN_PATH, "change_account", "interactive.rb")
if File.exist?(chaban)
require chaban
end
Plugin.create(:mikuttertyphooooooooooooooooooon) {
EVENT_ID = "TC1518"
Plugin[:openimg].addsupport(/^http:\/\/www\.amecs\.co\.jp\/wx\/typhoon\/.+\/[^\/]+\.html$/, nil) { |url, cancel|
if url =~ /^http:\/\/www\.amecs\.co\.jp\/wx\/typhoon\/.+\/([^\/]+).html$/
"http://www.amecs.co.jp/wx/data/typhoon/#{$1}.png"
else
nil
end
}
module Looper
def self.start(timer_set, &proc)
proc.call
Reserver.new(timer_set.call) { start(timer_set, &proc) }
end
end
Looper.start(lambda { 600 }) {
begin
json = Net::HTTP.get("api.aitc.jp", "/jmardb/search?eventid=#{EVENT_ID}&order=new")
data = JSON.parse(json)["data"].find { |_| _["headline"][0] }
text = data["headline"][0]
date = Time.parse(data["datetime"])
if !@last_date || (@last_date < date)
Delayer.new {
msg = Message.new(:message => "ぴんぽんぱんぽーん♪\n#{date.day}日#{date.hour}時#{date.min}分の台風情報です。\n\n#{text}", :system => true, :modified => Time.now + 1200, :confirm => {"OK" => 1}, :confirm_callback => lambda { |a|
msg[:modified] = Time.now
Plugin.call(:message_modified, msg)
})
msg[:entities] = {
:urls => [
{
:expanded_url => "http://www.amecs.co.jp/wx/typhoon/1/#{EVENT_ID.downcase}.html"
}
]
}
timeline(:home_timeline) << msg
}
end
@last_date = date
rescue => e
puts e
puts e.backtrace
end
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment