Created
April 2, 2014 15:03
-
-
Save sasamijp/9936006 to your computer and use it in GitHub Desktop.
天海春香さん生誕祭カウントダウンプログラムを作り忘れてて30分前に慌てて書いた
This file contains 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
# -*- encoding: utf-8 -*- | |
require 'tweetstream' | |
require 'twitter' | |
require 'date' | |
require './key.rb' | |
rest = Twitter::REST::Client.new do |config| | |
config.consumer_key = Const::CONSUMER_KEY | |
config.consumer_secret = Const::CONSUMER_SECRET | |
config.access_token = Const::ACCESS_TOKEN | |
config.access_token_secret = Const::ACCESS_TOKEN_SECRET | |
end | |
TweetStream.configure do |config| | |
config.consumer_key = Const::CONSUMER_KEY | |
config.consumer_secret = Const::CONSUMER_SECRET | |
config.oauth_token = Const::ACCESS_TOKEN | |
config.oauth_token_secret = Const::ACCESS_TOKEN_SECRET | |
config.auth_method = :oauth | |
end | |
alreadyposted3 = false | |
alreadyposted2 = false | |
alreadyposted1 = false | |
alreadyposted0 = false | |
timetobirth = Thread.new do | |
loop do | |
day = Time.now | |
if day.day == 2 and day.hour == 23 and day.min == 59 and day.sec == 57 and !alreadyposted3 | |
rest.update("3") | |
alreadyposted3 = true | |
end | |
if day.day == 2 and day.hour == 23 and day.min == 59 and day.sec == 58 and !alreadyposted2 | |
rest.update("2") | |
alreadyposted2 = true | |
end | |
if day.day == 2 and day.hour == 23 and day.min == 59 and day.sec == 59 and !alreadyposted1 | |
rest.update("1") | |
alreadyposted1 = true | |
end | |
if day.day == 3 and !alreadyposted0 | |
rest.update("0") | |
alreadyposted0 = true | |
end | |
end | |
end | |
client = TweetStream::Client.new | |
client.userstream do |status| | |
if status.text.include?("@sa2mi birth") and !status.text.start_with?("RT") | |
day = Time.now | |
message = "残り 0時間#{59-day.min}分 #{60-day.sec}秒" | |
text = "@#{status.user.screen_name} #{message}" | |
option = {"in_reply_to_status_id"=>status.id.to_s} | |
rest.update text,option | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment