Tag Archives: Programming

This morning I was looking at Wikipedia pages about cellular automata and I got an urge to implement Conway’s Game of Life as a Java exercise. This is what I came up with. It generates a random matrix for the starting position that then iteratively evolves in accordance with the Rules of the Game.

I have been writing a Twitter client in Python based on Mike Verdone’s Python Twitter Tools. It’s an elegant and concise library that allows access to all the useful parts of the Twitter API from inside a Python application. Unfortunately, the documentation is bad to non-existent.

After much fiddling I figured out how to use it for OAuth authentication. I’m sharing it here to save the next person the trouble. The first step if of course to import the twitter module. I like to import the oauth_dance portion of it too. This is needed to get the token key and token secret that give the application access to your Twitter account.

import twitter
import twitter.oauth_dance

You will need the consumer key and consumer secret, which you can get by registering your application with Twitter. Once you have done that just stick them in variables. As we don’t yet have the token key or secret, we pass empty strings for them. We then use parse_oauth_tokens in oauth_dance to get the token key and token secret and assign them to variables.

Now we open a web browser and point it at an URL based on the value in oauth_token. The user is asked to enter their login details and confirm that they want to allow the application to access their Twitter account. Then the user is given a PIN that we use in the next stage to complete the OAuth process.

Because my application is based on Python and Qt, I get the PIN from a text field in a dialog box. It is an instance of Qt’s QLineEdit. It doesn’t matter how you do it as long as you get the PIN into a string that can be passed to the twitterConnect object.