Skip to content

Instantly share code, notes, and snippets.

@kimihito
Created October 10, 2012 17:18
Show Gist options
  • Save kimihito/3867034 to your computer and use it in GitHub Desktop.
Save kimihito/3867034 to your computer and use it in GitHub Desktop.
ボク用ポモドーロbot
#!/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)
puts "work"
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
case set
when [25, 5]
#msg = "@#{tweet.user.screen_name} pomodoro start"
sleep (work_time * 60)
puts "break"
sleep (rest_time * 60)
puts "work"
when [25, 15]
#msg = "@#{tweet.user.screen_name} pomodoro start"
sleep (work_time * 60)
puts "long break"
sleep (rest_time * 60)
puts "work"
end
}
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