Published in: Ruby
URL: http://snipplr.com/view/2352/twitter-from-the-command-line-using-curl/
Put this in a file called tweet.rb, then call as follows: ruby tweet.rb username "my tweet"
Or you can include your password in the command like so ruby twit.rb username:password "my tweet"
(note that this is hugely insecure as your password will wind up in your .history, not to mention being visible to shouldersurfers).
Updated: if a post is over the 140-character limit, the script prints back the part of the tweet that would not fit. This makes it easier to trim down overly long posts.
#!/usr/bin/env ruby #Usage: # ruby tweet.rb username:password "status message" def tweet (arguments) user, twit = arguments response = `curl -s -u #{user} -d status="#{twit}" http://twitter.com/statuses/update.xml | grep truncated` unless (response =~ /truncated>false</) puts "fail: Tweet failed. Check your user name and password." end end if (ARGV[1].length > 140) overlimit = ARGV[1].length - 140 offendingSubstring = ARGV[1][140, ARGV[1].length-1] puts %Q{FAIL: #{overlimit} characters over the 140-character limit:} puts %Q{\t"...#{offendingSubstring}"} elsif (ARGV.length != 2) || (ARGV[1] == "") puts %Q{usage: ruby tweet.rb <username> "This will be tweeted to Twitter."} else tweet(ARGV) end
You need to login to post a comment.
