#!/usr/bin/env python # Simple rugby score announcing bot # Copyright (C) 2008 Michael Gorven # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU Affero General Public License as # published by the Free Software Foundation, either version 3 of the # License, or (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU Affero General Public License for more details. # # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . from irclib import IRC from time import sleep from urllib2 import urlopen from BeautifulSoup import BeautifulSoup from threading import Timer channel = '#channel' nick = 'nick' server = 'irc.example.com' port = 6667 prev = '' def update(): global prev global connection scoref = urlopen('http://www.supersport.co.za/rugby/live.aspx?id=15797&type=reload') soup = BeautifulSoup(scoref.read()) scoref.close() score = soup.b.contents[0] + ' (' + soup.td.contents[2] + ')' print score if not prev == score: connection.privmsg(channel, score) prev = score t = Timer(60, update) t.start() def connected(connection, event): connection.join(channel) def disconnected(connection, event): exit(0) irc = IRC() connection = irc.server().connect(server, port, nick) connection.add_global_handler("welcome", connected) connection.add_global_handler("disconnect", disconnected) t = Timer(60, update) t.start() irc.process_forever()