43 lines
1.1 KiB
Python
43 lines
1.1 KiB
Python
#!/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()
|
|
|
|
server_name = q.vars['sv_hostname']
|
|
current_map = q.vars['mapname']
|
|
human_players_count = len([x for x in q.players if not x.bot])
|
|
bots_players_count = len([x for x in q.players if x.bot])
|
|
|
|
data = render_template('status.j2.html',\
|
|
server_name=server_name,\
|
|
current_map=current_map,\
|
|
human_players_count=human_players_count,\
|
|
bots_players_count=bots_players_count)
|
|
|
|
return data
|
|
|
|
def main():
|
|
""" main func """
|
|
app.run(host='::')
|
|
|
|
|
|
if __name__ == '__main__':
|
|
main()
|