FootieBot ownz your World Cup

The World Cup. It's been on (almost) everyones mind for the last month or so. A lot of people are also guessing out the scores for fun or profit. There are also leagues set up to compete on guessing out the scores. I participated in one of these set up by a colleague, fun and play, no money involved.
Let's make one thing clear. Sports doesn't interest me. At all. I have never been all that interested in football, or any other sports for that matter. But I do like to compete and when Janne, our CEO made a script to calculate scores for our previous betting league (Ice Hockey world championships?), it was like throwing down the gauntlet. On our company forum I swore I would create a bot to participate in the Football World Cup.
And so I did, and he's called FootieBot. Bolted together with Python and equipped with web page analyzing components and Twitter for communications - FootieBot bravely set out to go for win. And well, failed, and is now coming in last :)
Even though FootieBot didn't get the win, it was a fun little project and gave me a good reason to try the power of Python in automated web page handling. As said, FootieBot is completely automated, and scheduled on my phone to run every 5 minutes. The program flow in short;
- Log in to Veikkaajat.net and get the next matches
- Store matches in an SQLite database
- For any matches within the nex 24 hours, get hits from Twitter for the last 5 minutes. Twitter is searched with the official name of the country from the pages of FIFA.
- Store amount of hits in the db
- Calculate a likely result and submit to Veikkaajat.net
- If there is only 20 minutes to kick off, post result on Twitter and mark match as submitted to ensure post is only done once
- Python 2.5 or higher 2.x version is needed.
- simplejson (needed for Python 2.5 only, used by Twython)
- Twython (Twitter API)
- Mechanize (web page automation)
- BeautifulSoup (excellent HTML parser)
- SQLite3 for Python
For anyone interested, the code is posted below. It requires the Veikkaajat.net game ID and login details, and Twitter login details. Also some small changes have been made to it over time so it is possible the original World Cup winner and top player -parts are not bug free. Oh and Veikkaajat.net is a Finnish language website for organizing betting leagues. With small modifications the script could be used for any similar website.
Download the code here!












Comments (post a comment)