-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 4f2dfdf
Showing
5 changed files
with
112 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
token: IE04GZz1UA5P0EDraT0Ldw | ||
atoken: 344645908-vevg6lvuewt3rFsnRLxop7cGw3cBH4PBQsUICZSl | ||
asecret: JWKqU4B2A6H1wNENYWaqdg47QlBF2oBcAWeJ7vi9IAk | ||
secret: ygj7NWTI7Q5Jh1YUyYNgPO63QOgjiufm15skwpZKrOw | ||
pin: |
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
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 |
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
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 |
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
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 |
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
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 |