-
-
Save kimihito/3867175 to your computer and use it in GitHub Desktop.
ボク用ポモドーロbot
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
#!/usr/bin/env ruby | |
#-*- coding: utf-8 -*- | |
require 'twitter' | |
require 'user_stream' | |
require 'active_support' | |
require 'active_support/core_ext' | |
require 'enumerable/lazy' | |
UserStream.configure do |config| | |
config.consumer_key = 'YOUR COMSUMER KEY' | |
config.consumer_secret = 'YOUR COMSUMER SERCRET' | |
config.oauth_token = 'YOUR OAUTH TOKEN' | |
config.oauth_token_secret = 'YOUR OAUTH SERCRET' | |
end | |
Twitter.configure do |config| | |
config.consumer_key = 'YOUR COMSUMER KEY' | |
config.consumer_secret = 'YOUR COMSUMER SERCRET' | |
config.oauth_token = 'YOUR OAUTH TOKEN' | |
config.oauth_token_secret = 'YOUR OAUTH SERCRET' | |
end | |
def pomodoro(tweet) | |
work = Enumerator.new {|y| loop { y << 25 } } | |
rest = Enumerator.new {|y| loop { 3.times { y << 5 }; y << 15 } } | |
pomodoro = work.lazy.zip(rest) | |
pomodoro.each {|set| | |
work_time, rest_time = set | |
puts "work" | |
sleep work_time.minutes | |
puts rest_time > 5 ? "long break" : "break" | |
sleep rest_time.minutes | |
} | |
end | |
while true | |
begin | |
client = UserStream.client | |
client.endpoint = 'https://stream.twitter.com/' | |
client.post('/1/statuses/filter.json', track: "POMODORO TWEET") do |status| | |
pomodoro(status) | |
end | |
rescue => exc | |
p exc | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment