Um svg-badge ausgabe erweitert, steuerbar mit GET-Parameter ?format=svg|text
This commit is contained in:
parent
0c408b53c7
commit
46f6df8e2f
72
jitsi-log.py
72
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 <r31k@k4p5.de> 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):
|
||||
|
Loading…
Reference in New Issue
Block a user