ふぁぼったーで自分のふぁぼられが変化したらDMで知らせるようにするRubyスクリプト(OAuth対応)
ふぁぼったーでふぁぼられ総数を監視して変化したらDMで知らせるようにするPythonスクリプト - phithonの日記
例によってOAuth対応させたらRubyになってた。
twitterで自分のフォロワーが変化したらDMで知らせるようにするRubyスクリプト(OAuth対応) - phithonの日記
↑のAPIラッパーが必要です。
以下ソース
#!/usr/bin/env ruby # -*- coding: utf8 -*- $:.unshift(File.dirname(__FILE__)) require 'twitterapi' require 'net/http' CONSUMER_KEY = '' CONSUMER_SECRET = '' ACCESS_TOKEN = '' ACCESS_TOKEN_SECRET = '' OWNER_NAME ='' # DM送信先ユーザ if (ARGV.length != 1) puts "usage: " + $0 + " logFilePath" exit end LOG_PATH = ARGV[0] def sendDM(text) twitter = TwitterAPI.new(CONSUMER_KEY,CONSUMER_SECRET, ACCESS_TOKEN, ACCESS_TOKEN_SECRET, true) twitter.sendDM(OWNER_NAME, text) end newSum = 0 Net::HTTP.start('favotter.net', 80) {|http| response = http.get('/user/' + OWNER_NAME) if (response.code != '200') puts 'response code: ' + response.code exit end contents = response.body titleStart = contents.index('<title>') title = contents[titleStart..contents.index('</title>', titleStart)] newSum = title[title.rindex('(')+1..title.rindex(')')-1].to_i } puts 'new: ' + newSum.to_s oldSum = 0 if (FileTest.exists?(LOG_PATH)) File::open(LOG_PATH) {|f| oldSum = f.read.to_i} puts 'old: ' + oldSum.to_s if newSum != oldSum sendDM('ふぁぼられ数が変化しました。(' + newSum.to_s + ')') File::open(LOG_PATH, 'w') {|f| f.print(newSum)} end else sendDM('ふぁぼられ数の記録を開始します。(' + newSum.to_s + ')') File::open(LOG_PATH, 'w') {|f| f.print(newSum)} end