Skip to content

Commit

Permalink
Initial import
Browse files Browse the repository at this point in the history
  • Loading branch information
suttree committed Jul 29, 2011
0 parents commit 4f2dfdf
Show file tree
Hide file tree
Showing 5 changed files with 112 additions and 0 deletions.
6 changes: 6 additions & 0 deletions .twitter
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
token: IE04GZz1UA5P0EDraT0Ldw
atoken: 344645908-vevg6lvuewt3rFsnRLxop7cGw3cBH4PBQsUICZSl
asecret: JWKqU4B2A6H1wNENYWaqdg47QlBF2oBcAWeJ7vi9IAk
secret: ygj7NWTI7Q5Jh1YUyYNgPO63QOgjiufm15skwpZKrOw
pin:
6 changes: 6 additions & 0 deletions .twitter.bak
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
token: UHmVI0JLmYkapqBFXj0RzQ
atoken: 193723613-QsWjYIfoY0V26WUaYLUzQDDf94Bnh46tjNGvSUqg
asecret: Qj93wMUH7Mse6MkX7Qlu9zulc4laDvIB0G0sPSJ6HF4
secret: 0KetN5Mn3Nzn8HKRTVxcymlUrhO7gbwIkXCqpoHCfZY
pin: 6583652
21 changes: 21 additions & 0 deletions README
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
worryee
=======

SETUP

- Go to https://dev.twitter.com/apps and create a new application
- Add the relevant tokens to the .twitter file
- Add an entry to your cron file to run the script as often as you'd like

CRON EXAMPLES

- Early each weekday morning:
30 6 * * 1-5 /usr/bin/ruby /home/suttree/src/twitter/worryee/worryee.rb >> /dev/null 2>&1

- On the hour, every hour:
@hourly /usr/bin/ruby /home/suttree/src/twitter/trainee/traintimes.rb >> /dev/null 2>&1

TWITTER SETUP

- Go to http://twitter.com/apps and register an application that you will use to send DMs, and subsequently SMSs, to yourself.
- Then edit your twitter mobile settings at http://twitter.com/devices
38 changes: 38 additions & 0 deletions helpers/config_store.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
class ConfigStore
attr_reader :file

def initialize(file)
@file = file
end

def load
@config ||= YAML::load(open(file))
self
end

def [](key)
load
@config[key]
end

def []=(key, value)
@config[key] = value
end

def delete(*keys)
keys.each { |key| @config.delete(key) }
save
self
end

def update(c={})
@config.merge!(c)
save
self
end

def save
File.open(file, 'w') { |f| f.write(YAML.dump(@config)) }
self
end
end
41 changes: 41 additions & 0 deletions worryee.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
require 'rubygems'
require 'twitter'
require 'open-uri'

require File.join(File.dirname(__FILE__), 'helpers', 'config_store')
config = ConfigStore.new(File.join(File.dirname(__FILE__), '.twitter'))
oauth = Twitter::OAuth.new(config['token'], config['secret'])

if config['atoken'] && config['asecret']
oauth.authorize_from_access(config['atoken'], config['asecret'])
twitter = Twitter::Base.new(oauth)

elsif config['rtoken'] && config['rsecret']
oauth.authorize_from_request(config['rtoken'], config['rsecret'], config['pin'])
twitter = Twitter::Base.new(oauth)

config.update({
'atoken' => oauth.access_token.token,
'asecret' => oauth.access_token.secret,
}).delete('rtoken', 'rsecret')
else
config.update({
'rtoken' => oauth.request_token.token,
'rsecret' => oauth.request_token.secret,
})

puts <<EOS
Visit #{oauth.request_token.authorize_url} in your browser to authorize the app,
then enter the PIN you are given:
EOS

pin = STDIN.readline.chomp
config.update({ 'pin' => pin })
exit('Run this script again, now that you are authorised')
end

if (1 + rand(6) == 6)
twitter.direct_message_create('suttree', "What are you worried about?")
else
puts "Nothing to worry about"
end

0 comments on commit 4f2dfdf

Please sign in to comment.