1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
## twitter-drip.rb
#!/usr/bin/env ruby

# Make a file in $HOME called tweets and put one tweet per line.
# in crontab
# 1 * * * * cd /path/to/script_dir/ && ruby twitter-drip.rb > /dev/null 2>&1
# then ever hour, a tweet will be dripped to twitter

require 'net/http'

TWEET_FILE = File.join(ENV["HOME"], "tweets")
TWITTER_USER = "" # your twitter username
TWITTER_PASS = "" # twitter password

# read all the pending tweets into an array
tweets = open(TWEET_FILE).readlines

# get the first one and remove it from the array
tweet = tweets.shift

open(TWEET_FILE, "w") do |file|  
  file.write(tweets.join)
end

if tweet
  # post the tweet
  res = Net::HTTP.post_form(URI.parse("http://#{TWITTER_USER}:#{TWITTER_PASS}@twitter.com/statuses/update.json"),
    {'status' => tweet[0..140]}
  )
  puts res.body
end