Simple twitter client written in Python

So… I finally got started looking at Python as a programming language. In my job I work with Java, and I never really done any other programming in another language. But I decided to throw myself at Python to see what the hype was all about. The problem with learning a new language, at least in my head, is that I need something to program. I need at specific problem to address. And now that I’m starting to use Twitter more and more, I decided to see what I could do with Python and the Twitter API. Doing some Google searching a found a very simple example of accessing Twitter through the API with Python. I found a guide here: Python/Twitter example I might need to say, that I did this on Ubuntu 9.10. So the first step was installing a python-twitter library:

sudo apt-get install python-twitter

Then I created a

termtwit.py

with Vim, (I prefer Vim for basic text editing), and I basically just copy/pasted the code from the site I linked to above. So the file ended up looking like this:

import twitter

username = "your_username"
password = "your_password"
api = twitter.Api(username=username, password=password)
statuses = api.GetFriendsTimeline(username)
for s in statuses :
print s.user.name.encode("utf-8"), "(", s.user.screen_name, ") :"
print s.text.encode("utf-8")
print

Run the file like this:

python termtwit.py

and It’ll show you the latest updates. So there you have it. Google the twitter API to learn more about the functions…

This entry was posted in Programming and tagged , , , , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>