Skip to content

Instantly share code, notes, and snippets.

@devyn
Created August 22, 2009 07:59
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 devyn/172702 to your computer and use it in GitHub Desktop.
Save devyn/172702 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
require 'rubygems'
require 'json'
require 'uri'
require 'net/http'
$tw_user = "<twitter_username>"
$tw_pass = "<twitter_password>"
case ARGV[0]
when '-l'
res = JSON.load(Net::HTTP.start('www.twitter.com'){|http|get=Net::HTTP::Get.new("/statuses/friends_timeline.json?count=#{ARGV[1].to_i||10}"); get.basic_auth $tw_user, $tw_pass; http.request(get).body})
res.each do |st|
printf "\e[33m\e[1m%-20s\e[22m \e[36m%s\e[0m\n", st['user']['screen_name'], st['text']
end
when String
res = JSON.load(Net::HTTP.post_form(URI::HTTP.build(:host => 'www.twitter.com', :path => '/statuses/update.json', :userinfo => "#$tw_user:#$tw_pass"), 'status' => ARGV.join(" ")).body)
if res['error']
puts "Error: #{res['error']}"
else
puts "Successfully posted new status."
end
else
puts "\e[1m\e[33m~devyn's Twitter Client\e[0m"
puts "\e[36m I spend my time at the linux console for most of my day,"
puts "\e[36m so I need an easy way to tweet, otherwise I won't do it at all.\e[0m"
puts
puts "\e[36mUsage:\e[0m \e[1mtweet\e[0m \e[31m<status>\e[0m \e[36m# Post a status update\e[0m"
puts " \e[1mtweet -l\e[0m \e[32m[\e[0m\e[31mn=10\e[0m\e[32m]\e[0m \e[36m# Latest tweets, where n is a number from 1 to 200, how many to fetch\e[0m"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment