From 46f6df8e2fbd20e0ce776d3527c661725c529d8f Mon Sep 17 00:00:00 2001 From: Reiko Kaps Date: Fri, 19 Jun 2020 17:52:00 +0200 Subject: [PATCH] Um svg-badge ausgabe erweitert, steuerbar mit GET-Parameter ?format=svg|text --- jitsi-log.py | 72 ++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 56 insertions(+), 16 deletions(-) diff --git a/jitsi-log.py b/jitsi-log.py index 41b3c73..2af13bd 100755 --- a/jitsi-log.py +++ b/jitsi-log.py @@ -1,5 +1,8 @@ #!/bin/env python3 # +# simple log parser and status server for the jitsi meet video conference tool +# +# Reik Kaps 2020 import re import sys @@ -9,10 +12,11 @@ from os.path import basename from datetime import datetime from argparse import ArgumentParser from http.server import BaseHTTPRequestHandler, HTTPServer -from urllib.parse import urlparse +from urllib.parse import urlparse, parse_qs try: from sh import tail + from pybadges import badge except ImportError as e: print('[Error] Please install sh via pip! {}'.format(e)) @@ -75,7 +79,6 @@ 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) @@ -90,22 +93,59 @@ class logThread(threading.Thread): class MyServer(BaseHTTPRequestHandler): + def badge_respones(self, response_string): + self.send_response(200) + self.send_header("Content-type", "image/svg+xml") + self.end_headers() + self.wfile.write(response_string) + + def text_response(self, response_string): + self.send_response(200) + self.send_header("Content-type", "text/plain") + self.end_headers() + self.wfile.write(response_string) + def do_GET(self): - if basename(self.path) in roomList: - self.send_response(200) - self.send_header("Content-type", "text/plain") - self.end_headers() - response_string = bytes(basename(self.path) - + '|' - + str(roomList[basename(self.path)].ctime) - + '|' - + str(len(roomList[basename(self.path)].members)) - + '|', "utf-8") - self.wfile.write(response_string) + query_components = parse_qs(urlparse(self.path).query) + if "format" in query_components: + respones_format = query_components["format"][0] else: - self.send_response(404) - self.send_header("Content-type", "text/plain") - self.end_headers() + respones_format = 'text' + + room_name = basename(self.path.split('?')[0]) + print('{} - {}'.format(query_components, room_name)) + if room_name in roomList: + if respones_format == 'json': + pass + elif respones_format == 'svg': + s = badge(left_text='{}: {}'.format('Room', room_name), + right_text=str(len(roomList[room_name].members)), + left_color='blue', + right_color='green') + response_string = bytes(s, "utf-8") + self.badge_respones(response_string) + + else: + # default text response + response_string = bytes(room_name + + '|' + + str(roomList[room_name].ctime) + + '|' + + str(len(roomList[room_name].members)) + + '|', "utf-8") + self.text_response(response_string) + else: + if respones_format == 'svg': + s = badge(left_text='{}: {}'.format('Room', room_name), + right_text='empty', + left_color='red', + right_color='darkgray') + response_string = bytes(s, "utf-8") + self.badge_respones(response_string) + else: + self.send_response(404) + # self.send_header("Content-type", "text/plain") + self.end_headers() def getRoomName(jid):