電力使用状況APIを使って電力の最大供給量と使用量から利用率を求め,Growlで表示するスクリプトを作ってみました。
lpu.rb
#!/usr/bin/env ruby # -*- coding: utf-8 -*- # latestPowerUsage - lpu.rb require 'open-uri' require 'json' require 'ruby-growl' APPID = "__Your Application ID__" # アプリケーションIDを記入 json = URI("http://setsuden.yahooapis.jp/v1/Setsuden/latestPowerUsage?appid=#{APPID}&output=json").read hash = JSON.parse(json) usage = hash["ElectricPowerUsage"]["Usage"]["$"] capacity = hash["ElectricPowerUsage"]["Capacity"]["$"] date = hash["ElectricPowerUsage"]["Date"] hour = hash["ElectricPowerUsage"]["Hour"] g = Growl.new "localhost", "ruby-growl", ["ruby-growl Notification"] g.notify "ruby-growl Notification", "tokyo electric power company", sprintf("%s %s時現在の利用率: %.1f\%", date, hour, 100.0*usage/capacity), 0, true