Last active
August 29, 2015 14:13
-
-
Save rococodogs/93f6d5bb4dc7ba0bd703 to your computer and use it in GitHub Desktop.
one of these days i'll learn to use ruby in an oop manner
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
require "yaml" | |
require "twitter" | |
require "net/http" | |
require "json" | |
config = YAML.load_file("config.yml"); | |
client = Twitter::REST::Client.new do |c| | |
c.consumer_key = config['consumer_key'] | |
c.consumer_secret = config['consumer_secret'] | |
c.access_token = config['access_token'] | |
c.access_token_secret = config['access_token_secret'] | |
end | |
latest = client.user_timeline.first.full_text | |
new_tweet = [] | |
attempts = 0 | |
char_count = 0 | |
latest.split(' ').each do | word | | |
break if attempts == config['wordsapi_hourly_limit'] | |
wordsapi_uri = URI("https://www.wordsapi.com/words/#{word}/synonyms?accessToken=#{config["wordsapi_token"]}") | |
res = JSON.parse Net::HTTP.get(wordsapi_uri) | |
attempts += 1 | |
sel = res['synonyms'].sample | |
if (char_count += sel.length + 1) <= 140 | |
new_tweet.push sel | |
else | |
break | |
end | |
end | |
client.update new_tweet.join(' ') |
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
# twitter keys to fill in | |
# https://dev.twitter.com | |
consumer_key: | |
consumer_secret: | |
access_token: | |
access_token_secret: | |
# wordsapi token to fill in | |
# + limit (1,000 per day / 24 hours) | |
# https://www.wordsapi.com | |
wordsapi_token: | |
wordsapi_hourly_limit: 40 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment