Skip to content

Instantly share code, notes, and snippets.

@HITGIF
Last active December 28, 2017 02:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save HITGIF/dc95f9a95a8672fe05c6df227239561e to your computer and use it in GitHub Desktop.
Save HITGIF/dc95f9a95a8672fe05c6df227239561e to your computer and use it in GitHub Desktop.
Fuse-Delay Tweeting
{
"consumer_key": "YOUR_CONSUMER_KEY",
"consumer_secret": "YOUR_CONSUMER_SECRET",
"access_token": "YOUR_ACCESS_TOKEN",
"access_token_secret": "YOUR_ACCESS_TOKEN_SECRET",
"tweets":[
"Hello",
"World"
]
}
#
# Fuse-Delay Tweeting
# A command line Ruby script that
# waits for (user supplied) seconds
# before posting a (user supplied) tweet.
#
# Usage:
# Edit the config.json in the same path
# with your tweet messages and token.
#
# Sample Command (Delay 5 seconds):
# $ ruby fdTweet.rb -t=5
#
require 'rubygems'
require 'twitter'
require 'json'
# Read config.json
file = File.read 'config.json'
data = JSON.parse(file)
# Parse Command Line Arguments
args = Hash[ARGV.join(' ').scan(/--?([^=\s]+)(?:=(\S+))?/)]
if data
# Read Tweets
Array tweets = data['tweets']
# Read Config
client = Twitter::REST::Client.new do |config|
config.consumer_key = "data['consumer_key']"
config.consumer_secret = "data['consumer_secret']"
config.access_token = "data['access_token']"
config.access_token_secret = "data['access_token_secret']"
end
# Send Tweet
tweets.each do |tweet|
# Delay each tweet for a given number of seconds
if args['t'] then sleep(Integer(args['t'])) end
client.update(tweet)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment