~ubuntu-branches/debian/sid/calligraplan/sid

« back to all changes in this revision

Viewing changes to devtools/scripts/ircbuildbot.py

  • Committer: Package Import Robot
  • Author(s): Pino Toscano
  • Date: 2018-02-01 18:20:19 UTC
  • Revision ID: package-import@ubuntu.com-20180201182019-1qo7qaim5wejm5k9
Tags: upstream-3.1.0
ImportĀ upstreamĀ versionĀ 3.1.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/python -Qwarnall
 
2
# -*- coding: utf-8 -*-
 
3
 
 
4
# This is a simple irc bot that reports progress to the Calligra irc channel
 
5
 
 
6
import time, lxml.etree, urllib2, re, sys, socket, string
 
7
 
 
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
 
11
IDENT='buildbot_py'
 
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 
 
16
 
 
17
feed = "http://158.36.191.251:8080/guestAuth/feed.html?buildTypeId=bt6&itemsType=builds&buildStatus=failed&userKey=guest"
 
18
 
 
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
 
23
 
 
24
def getMessage():
 
25
        try:
 
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
 
34
                try:
 
35
                        who = re.search('by\s+(\S*)', summary).group(1)
 
36
                        newmessage = who + ": " + newmessage
 
37
                except:
 
38
                        pass
 
39
        except:
 
40
                newmessage = "Error in reading RSS"
 
41
        return newmessage
 
42
 
 
43
joined = False
 
44
message = ""
 
45
lastchecktime = time.time() - 55
 
46
while 1:
 
47
        line = s.recv(500) #receive server messages
 
48
        print line.rstrip() #server message is output
 
49
        if not joined:
 
50
                s.send('JOIN ' + CHANNELINIT + '\n') #Join a channel
 
51
                s.send("PRIVMSG " + CHANNELINIT + " :Spawned, James Spawned\n")
 
52
                joined = True
 
53
        if line[:4] == "PING":
 
54
                s.send("PONG\n")
 
55
        if time.time() - lastchecktime > 60:
 
56
                newmessage = getMessage()
 
57
                if newmessage != message:
 
58
                        message = newmessage
 
59
                        s.send("PRIVMSG " + CHANNELINIT + " :" + message + "\n")
 
60
                lastchecktime = time.time()