Skip to content

Instantly share code, notes, and snippets.

@adamloving
Created May 26, 2014 23:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save adamloving/f87489caef86acc475d7 to your computer and use it in GitHub Desktop.
Save adamloving/f87489caef86acc475d7 to your computer and use it in GitHub Desktop.
Post several links to twitter feed
#!/usr/bin/env ruby
# foreman run script/social/auto-tweet.rb data/crawl-data.json
require 'Twitter'
require 'json'
client = Twitter::REST::Client.new do |config|
config.consumer_key = ENV['TWITTER_API_KEY']
config.consumer_secret = ENV['TWITTER_API_SECRET']
config.access_token = ENV['TWITTER_ACCESS_TOKEN']
config.access_token_secret = ENV['TWITTER_ACCESS_TOKEN_SECRET']
end
urls = JSON.parse(File.open(ARGV.first).read)
# todo. add hashtags
for url in urls[2..50]
text = url['description'] || url['title']
tweet = "#{text[0..100]} #{url['url']}"
client.update(tweet)
Kernel.sleep(2)
end
@adamloving
Copy link
Author

Requires a data file in the format:

[{
  "url": "http://www.glutenfreefancy.com/gluten-allergy-test/quiz",
  "title": "Gluten Free Fancy",
  "description": "Are you gluten intolerant? Take this 1 minute quiz to find out."
}, ...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment