#!/usr/bin/python import urllib, urllib2 from sys import stdin, stdout, stderr email="your email address" password="your twitter password" body = "" line = stdin.readline() while line: if line == ".\n": break else: body += line line = stdin.readline() class MessageError(Exception): pass if len(body) > 140: raise MessageError, "Message is more than 140 characters." def twitterPost(email, password, message): # Create an OpenerDirector with support for Basic HTTP Authentication... auth_handler = urllib2.HTTPBasicAuthHandler() auth_handler.add_password('Twitter API', 'twitter.com', email, password) opener = urllib2.build_opener(auth_handler) # ...and install it globally so it can be used with urlopen. urllib2.install_opener(opener) data = urllib.urlencode({"status" : body}) res = urllib2.urlopen("http://twitter.com/statuses/update.xml", data) twitterPost(email, password, body)