Created
July 23, 2008 17:27
-
-
Save caffo/1821 to your computer and use it in GitHub Desktop.
simple fortune / twitter bot
This file contains hidden or 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
#!/usr/bin/ruby | |
# fortunebot.rb - simple fortune / twitter bot | |
# non-copyright (c) 2008 rodrigo franco <[email protected]> | |
# | |
# 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