Twitter Command Line
- Posted: 3 years ago
- Tags:code, ruby, twitter
- 0 comments
I always have a dozen terminals open, so I figured it was time to make a way to post to twitter from the command line. This is extremely simple and can probably be improved, but for now this is working for me:
#!/usr/bin/env ruby
require 'rubygems'
require 'twitter'
if ARGV.size == 0
puts "\tUsage: tweet i like to eat cheese"
exit
end
#Load Configuration from ~/.twitter
begin
config = YAML::load(open(ENV['HOME'] + '/.twitter'))
rescue
puts "\tConfiguration File Missing"
puts "\tExample:\n\n"
puts "\tlogin: mylogin"
puts "\tpassword: mypassword"
puts "\n\tput in ~/.twitter\n"
exit
end
#initialize twitter library
twitter = Twitter::Base.new(config['login'], config['password'])
message = ARGV.join(' ').gsub(/"/, '')
status = twitter.post(message)
puts "\t\tTweet Posted: http://twitter.com/#{status.user.name}/statuses/#{status.id}\n"
Remember to 'gem install twitter' as root, or run as sudo, and also to put your configuration file in ~/.twitter. There is an example in the usage output of the script.
Update: I posted a new and slightly improved version of this for Download here. This version will print out tweets for you if ran with no parameters, and will post any parameters you do use straight to twitter. Also, I found out that the twitter gem I am using already has a decent cli interface. Read about it here.
Comments:
| No Comments Posted |
Add Comment:
Back
