Skip to content

Instantly share code, notes, and snippets.

@caffo
Created July 23, 2008 17:27
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 caffo/1821 to your computer and use it in GitHub Desktop.
Save caffo/1821 to your computer and use it in GitHub Desktop.
simple fortune / twitter bot
#!/usr/bin/ruby
# fortunebot.rb - simple fortune / twitter bot
# non-copyright (c) 2008 rodrigo franco <caffo@imap.cc>
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
# DEALINGS IN THE SOFTWARE.
#
require 'rubygems'
require 'twitter' # (twitter4r)
require 'time'
# Twitter bot configuration
TWITTER_USER = 'foobar'
TWITTER_PASS = 'foobar'
TWITTER = Twitter::Client.new(:login => TWITTER_USER, :password => TWITTER_PASS)
module FortuneBot
def self.generate_fortune
return(`/opt/local/bin/fortune -s`)
end
def self.twitterable_fortune
fortune = generate_fortune.gsub(/\t/,' ').gsub(/\n/,'').gsub(/--.*/,'').gsub("\"",'')
fortune.size > 140 ? twitterable_fortune : "#{fortune}"
end
def self.exec
status =TWITTER.status(:post, twitterable_fortune)
end
end
FortuneBot.exec
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment