Created
February 19, 2012 04:42
-
-
Save kimoto/1862015 to your computer and use it in GitHub Desktop.
UCCardの取引履歴に変化があったらim.kayac.comでiPhoneに通知デーモン
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
#!/bin/env ruby | |
# encoding: utf-8 | |
# Author: kimoto | |
require 'uc_card' | |
require 'yaml' | |
require 'im-kayac' | |
class Pit::ImKayac | |
def self.post(message, pit_key = "im.kayac.com") | |
config = Pit.get(pit_key, :require => { | |
:username => 'Please input your im.kayac.com Username' | |
}) | |
ImKayac.post(config[:username], message) | |
end | |
end | |
# 10分に一度 | |
# = 1時間に6回 | |
# = 1日144回 | |
wait_time = 60 * 10 | |
last_trades = nil | |
while true | |
trades = UCCard.start_with_pit("uccard.co.jp"){ |card| card.recent_shoppings } | |
if last_trades.nil? | |
# 初回は何もしない | |
# けど一応疎通確認のためになんか送ってみる(この場合は最新の取引データ1件) | |
Pit::ImKayac.post(trades.first.to_s) | |
else | |
diff = (trades.map(&:to_s) - last_trades.map(&:to_s)) | |
if not diff.empty? | |
diff.each{ |diff_trade| | |
Pit::ImKayac.post(diff_trade) | |
} | |
end | |
end | |
last_trades = trades | |
puts "waiting #{wait_time} seconds.." | |
sleep wait_time | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment