Created
July 2, 2012 16:16
-
-
Save cosmo0920/3034020 to your computer and use it in GitHub Desktop.
非公式関電APIのmikutterプラグインのプロトタイプ。
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
#!/usr/bin/env ruby -Ku | |
# -*- coding: utf-8 -*- | |
require "open-uri" | |
require "rubygems" | |
require "json" | |
require "time" | |
Plugin.create :teiden_kansai do | |
src = '' | |
group = "4-F" | |
begin | |
open("http://kteiden.chibiegg.net/api/kteiden.json?&group=#{group}"){|file| | |
src = file.read.gsub(/^\[/,"").gsub(/\]$/,"") #前後についている[]を取り払う | |
} | |
#jsonパーサーを使う | |
json = JSON.parser.new(src) | |
#突っ込むためのハッシュ作成 | |
h = Hash.new | |
h = json.parse() | |
source = h["source"].to_f | |
if source == 1 then | |
info = "月間予定" | |
elsif source == 2 then | |
info = "翌日予定" | |
elsif source == 3 then | |
info = "当日予定" | |
else | |
info = "情報なし" | |
end | |
if h["is_implemented"] then | |
is_impl = "実施有り" | |
else | |
is_impl = "実施無し" | |
end | |
t = Time.parse(h["date"]) | |
date = "日付 : " << t.year.to_s << "/" << t.month.to_s << "/" << t.day.to_s << "\n" | |
group = "グループ : " << h["group"] << "\n" | |
length = "計画停電対象時間 : "<< h["start"] << "から" << h["end"] << "まで\n" | |
bool = "計画停電の有無 : " << is_impl.to_s << "\n" | |
rank = "グループ内停電順位 : " << h["order"].to_s << "\n" | |
infosource = "情報源 : " << info << "\n" | |
bg_system("notify-send","関西停電情報", | |
"#{group}#{length}#{bool}#{rank}#{infosource}") | |
rescue JSON::ParserError | |
print "json parse error." | |
rescue OpenURI::HTTPError | |
print "Http bad request." | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment