diff --git a/jitsi-log.py b/jitsi-log.py index 2af13bd..182b9f2 100755 --- a/jitsi-log.py +++ b/jitsi-log.py @@ -48,6 +48,10 @@ owner = re.compile(owner_regex) member_regex = r"^Member\s(.*)@(.*)\/(.*)\sjoined." member = re.compile(member_regex) +# remove/leaving member +leaving_regex = r"^Member\s(.*)@(.*)\/(.*)\sis\sleaving" +leaving = re.compile(leaving_regex) + class MeetingRoom(): """ @@ -79,6 +83,7 @@ class MeetingRoom(): def __str__(self): return '{}: {}'.format(self.jid, self.owner) + class logThread(threading.Thread): def __init__(self, threadID, name, filename): threading.Thread.__init__(self) @@ -89,7 +94,6 @@ class logThread(threading.Thread): def run(self): while True: getLogMsg(self.filename) - sleep(5) class MyServer(BaseHTTPRequestHandler): @@ -169,7 +173,7 @@ def process_line(line): if new_room: room_name = getRoomName(new_room.group(2)) room_date = mkDatetime(erg.group(2), erg.group(3)) - print('{} {}'.format(room_date, room_name)) + print('{} {} created'.format(room_date, room_name)) currentRoom = MeetingRoom(room_name, room_date) if room_name in roomList: # delete old room and recreate it @@ -183,14 +187,12 @@ def process_line(line): room_name = disposed_room.group(1) print('-> room disposed: {}'.format(room_name)) if room_name in roomList: - del roomList[room_name] - + owner_match = owner.match(erg.group(7)) if owner_match: room_name = owner_match.group(1).strip() room_owner = owner_match.group(3).strip() - # print('{}: {}'.format(room_name, room_owner)) if room_name in roomList: roomList[room_name].setOwner(room_owner) @@ -198,10 +200,19 @@ def process_line(line): if member_match: room_name = member_match.group(1).strip() room_member = member_match.group(3).strip() - print('--> {}: {}'.format(room_name, room_member)) + print('{} enters {}'.format(room_member, room_name)) if room_name in roomList: roomList[room_name].addMember(room_member) + # participant is leaving a the room + leaving_match = leaving.match(erg.group(7)) + if leaving_match: + room_name = member_match.group(1).strip() + room_member = member_match.group(3).strip() + print('{} leaves {}'.format(room_member, room_name)) + if room_name in roomList: + roomList[room_name].delMember(room_member) + def getLogMsg(logfile): """ @@ -224,9 +235,9 @@ if __name__ == '__main__': parser.add_argument('--verbose', '-v', help='be verbose eg. for debugging', action='store_true') - parser.add_argument('--logwatch', '-w', - help='run as logwatch module, ' + - ' dont start the webserver and only run once') + parser.add_argument('--port', '-p', + help='set the http server port', + default=9999) args = parser.parse_args() @@ -234,11 +245,11 @@ if __name__ == '__main__': try: loggerThread = logThread(1, "Thread-Logger", args.log) loggerThread.start() - except: - print('Error: unable to start threads') + except Exception as e: + print('Error: unable to start threads {}'.format(e)) hostName = 'localhost' - serverPort = 9999 + serverPort = args.port webServer = HTTPServer((hostName, serverPort), MyServer) try: