Wednesday, April 22, 2009

Use Python to post to twitter

Here is an example of using python to post to twitter.

def twit(login, password, msg):

payload= {'status' : msg, 'source' : 'TinyBlurb'}
payload= urllib.urlencode(payload)

base64string = base64.encodestring('%s:%s' % (login, password))[:-1]
headers = {'Authorization': "Basic %s" % base64string}
url = "http://twitter.com/statuses/update.xml"

result = urlfetch.fetch(url, payload=payload, method=urlfetch.POST, headers=headers)

return result.content

No comments: