Wednesday 13 August 2008

Posting twitter messages from Python

I've been doing a quick test, trying to post twitter messages using Python, with the Twyt library.

Suppose you've got a piece of equipment, that you want to get a Twitter message from if some event occurs....

Here's a small piece of sample code to show how its done, based on Tony Gambone's Twitmon code:


#!/usr/bin/python
import twyt.twitter as twitter

username = "your_username"
password = "your_password"
if __name__ == "__main__":
t = twitter.Twitter()
try:
t.setauth(username, password)
except AttributeError:
t.set_auth(username, password)

text = "this is a test message"

try:
t.status_update(text)
except twitter.TwitterException, e:
print "Error! " + e


No comments: