File indexing completed on 2024-05-12 16:28:27
0001 #!/usr/bin/python -Qwarnall 0002 # -*- coding: utf-8 -*- 0003 0004 # This is a simple irc bot that reports progress to the Calligra irc channel 0005 0006 import time, lxml.etree, urllib2, re, sys, socket, string 0007 0008 HOST='irc.freenode.org' #The server we want to connect to 0009 PORT=6667 #The connection port which is usually 6667 0010 NICK='buildbot_py' #The bot's nickname 0011 IDENT='buildbot_py' 0012 REALNAME='James Spawned' 0013 OWNER='vandenoever' #The bot owner's nick 0014 CHANNELINIT='#Calligra' #The default channel for the bot 0015 readbuffer='' #Here we store all the messages from server 0016 0017 feed = "http://158.36.191.251:8080/guestAuth/feed.html?buildTypeId=bt6&itemsType=builds&buildStatus=failed&userKey=guest" 0018 0019 s = socket.socket( ) #Create the socket 0020 s.connect((HOST, PORT)) #Connect to server 0021 s.send('NICK '+NICK+'\n') #Send the nick to server 0022 s.send('USER '+IDENT+' '+HOST+' bla :'+REALNAME+'\n') #Identify to server 0023 0024 def getMessage(): 0025 try: 0026 parser = lxml.etree.XMLParser(dtd_validation=False, load_dtd=False, resolve_entities=False, no_network=False, recover=False) 0027 tree = lxml.etree.parse(urllib2.urlopen(feed)) 0028 ns = {'a':'http://www.w3.org/2005/Atom'} 0029 link = tree.xpath("/a:feed/a:entry[1]/a:link/@href", namespaces=ns)[0] 0030 title = tree.xpath("/a:feed/a:entry[1]/a:title/text()", namespaces=ns)[0] 0031 summary = tree.xpath("/a:feed/a:entry[1]/a:summary/text()", namespaces=ns)[0] 0032 s = re.search('strong>([^<]*)<', summary).group(1) 0033 newmessage = title + " " + s + " " + link 0034 try: 0035 who = re.search('by\s+(\S*)', summary).group(1) 0036 newmessage = who + ": " + newmessage 0037 except: 0038 pass 0039 except: 0040 newmessage = "Error in reading RSS" 0041 return newmessage 0042 0043 joined = False 0044 message = "" 0045 lastchecktime = time.time() - 55 0046 while 1: 0047 line = s.recv(500) #receive server messages 0048 print line.rstrip() #server message is output 0049 if not joined: 0050 s.send('JOIN ' + CHANNELINIT + '\n') #Join a channel 0051 s.send("PRIVMSG " + CHANNELINIT + " :Spawned, James Spawned\n") 0052 joined = True 0053 if line[:4] == "PING": 0054 s.send("PONG\n") 0055 if time.time() - lastchecktime > 60: 0056 newmessage = getMessage() 0057 if newmessage != message: 0058 message = newmessage 0059 s.send("PRIVMSG " + CHANNELINIT + " :" + message + "\n") 0060 lastchecktime = time.time()