q3_server_status/quake3_status.py

39 lines
910 B
Python
Raw Normal View History

2020-03-25 01:37:41 +01:00
#!/usr/bin/env python3.6
# -*- coding:utf-8 -*-
""" basic q3 status page for my home server """
from flask import Flask
from flask import render_template
from pyquake3 import PyQuake3
import os
# pylint: disable=invalid-name
app = Flask(__name__)
app.url_map.strict_slashes = False
@app.route('/')
def index(hours=None, minutes=None):
""" main and only app """
q3server = os.environ.get("Q3_SERVER")
rcon_password = os.environ.get("RCONN_PASSWORD")
q = PyQuake3(q3server, rcon_password)
q.update()
2020-04-17 01:03:48 +02:00
data = 'The name is %s, running map %s with %s human player(s) and %s bot(s).' % \
(q.vars['sv_hostname'], \
q.vars['mapname'], \
len([x for x in q.players if not x.bot]),\
len([x for x in q.players if x.bot]))
2020-03-25 01:37:41 +01:00
return data
def main():
""" main func """
app.run(host='::')
if __name__ == '__main__':
main()