1
#!/usr/bin/python -Qwarnall
2
# -*- coding: utf-8 -*-
4
# This is a simple irc bot that reports progress to the Calligra irc channel
6
import time, lxml.etree, urllib2, re, sys, socket, string
8
HOST='irc.freenode.org' #The server we want to connect to
9
PORT=6667 #The connection port which is usually 6667
10
NICK='buildbot_py' #The bot's nickname
12
REALNAME='James Spawned'
13
OWNER='vandenoever' #The bot owner's nick
14
CHANNELINIT='#Calligra' #The default channel for the bot
15
readbuffer='' #Here we store all the messages from server
17
feed = "http://158.36.191.251:8080/guestAuth/feed.html?buildTypeId=bt6&itemsType=builds&buildStatus=failed&userKey=guest"
19
s = socket.socket( ) #Create the socket
20
s.connect((HOST, PORT)) #Connect to server
21
s.send('NICK '+NICK+'\n') #Send the nick to server
22
s.send('USER '+IDENT+' '+HOST+' bla :'+REALNAME+'\n') #Identify to server
26
parser = lxml.etree.XMLParser(dtd_validation=False, load_dtd=False, resolve_entities=False, no_network=False, recover=False)
27
tree = lxml.etree.parse(urllib2.urlopen(feed))
28
ns = {'a':'http://www.w3.org/2005/Atom'}
29
link = tree.xpath("/a:feed/a:entry[1]/a:link/@href", namespaces=ns)[0]
30
title = tree.xpath("/a:feed/a:entry[1]/a:title/text()", namespaces=ns)[0]
31
summary = tree.xpath("/a:feed/a:entry[1]/a:summary/text()", namespaces=ns)[0]
32
s = re.search('strong>([^<]*)<', summary).group(1)
33
newmessage = title + " " + s + " " + link
35
who = re.search('by\s+(\S*)', summary).group(1)
36
newmessage = who + ": " + newmessage
40
newmessage = "Error in reading RSS"
45
lastchecktime = time.time() - 55
47
line = s.recv(500) #receive server messages
48
print line.rstrip() #server message is output
50
s.send('JOIN ' + CHANNELINIT + '\n') #Join a channel
51
s.send("PRIVMSG " + CHANNELINIT + " :Spawned, James Spawned\n")
53
if line[:4] == "PING":
55
if time.time() - lastchecktime > 60:
56
newmessage = getMessage()
57
if newmessage != message:
59
s.send("PRIVMSG " + CHANNELINIT + " :" + message + "\n")
60
lastchecktime = time.time()