Go4Expert (http://www.go4expert.com/)
-   Web Development (http://www.go4expert.com/forums/web-development-forum/)
-   -   Send Twitter update using Python (http://www.go4expert.com/forums/send-twitter-update-using-python-t24569/)

pein87 17Jan2011 10:08

Send Twitter update using Python
Well I've been reading this book called "head first beginning programming" so I can learn Python without all the bloat of normal Python books. I modified a function that they used to accept your username and password as parameters. I might add string length checking to so that you dont get errors for the message being to long.

Code: Python

# includes start

import urllib.request

#includes end

def sendTwitterUpdate(msg,twitUserName,twitPassword):
    passManager = urllib.request.HTTPPasswordMgr()
    passManager.add_password("Twitter API","http://twitter.com/statuses",twitUserName,twitPassword)
    httpHandle = urllib.request.HTTPBasicAuthHandler(passManager)
    pageOpener = urllib.request.build_opener(httpHandle)
    params = urllib.parse.urlencode({'status': msg})
    response = urllib.request.urlopen("http://twitter.com/statuses/update.json", params)

All times are GMT +5.5. The time now is 05:20.