summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndré Glüpker <git@wgmd.de>2018-03-30 12:58:27 +0200
committerAndré Glüpker <git@wgmd.de>2018-03-30 12:59:42 +0200
commit798aa8ec3d6889faf938cc3316d76a7ef2c6ac41 (patch)
treec11e8bbfe9ef80ce4822d04d5cc212c0b1b1dd7f
parent2c07560dab55c4c8e6f9885451488f96c7fc2338 (diff)
downloadsteam-798aa8ec3d6889faf938cc3316d76a7ef2c6ac41.tar.gz
steam-798aa8ec3d6889faf938cc3316d76a7ef2c6ac41.tar.bz2
steam-798aa8ec3d6889faf938cc3316d76a7ef2c6ac41.zip
Query servers in parallel and check for updates
-rwxr-xr-xmain.py28
-rw-r--r--static/style.css5
-rw-r--r--templates/server_html.jinja3
3 files changed, 34 insertions, 2 deletions
diff --git a/main.py b/main.py
index 2a1f51b..823b31f 100755
--- a/main.py
+++ b/main.py
@@ -4,6 +4,7 @@ from flask import Flask, flash, redirect, render_template, request, session, url
# from wsgiref.util import setup_testing_defaults
from collections import OrderedDict
+from concurrent.futures import ThreadPoolExecutor
import json
import os
@@ -172,8 +173,31 @@ def premades():
def server():
with open(os.path.join(CONFIG, 'server.json'), 'rt') as config:
servers = json.load(config)
- for name, server in servers.items():
- server['data'] = QueryServer.QueryServer(server['ip'], server['port'], server['gameid'])
+
+ executor = ThreadPoolExecutor(max_workers=10)
+ serverdata_ = dict()
+ for _, serverdata in servers.items():
+ name = "{0}{1:d}{2:d}".format(serverdata['ip'], serverdata['port'], serverdata['gameid'])
+ serverdata_[name] = executor.submit(
+ QueryServer.QueryServer,
+ serverdata['ip'],
+ serverdata['port'],
+ serverdata['gameid']
+ )
+
+ for _, serverdata in servers.items():
+ name = "{0}{1:d}{2:d}".format(serverdata['ip'], serverdata['port'], serverdata['gameid'])
+ serverdata['data'] = serverdata_[name].result()
+ serverdata_['u' + name] = executor.submit(
+ steam.getGameUpdateState,
+ serverdata['data']['gameid'],
+ serverdata['data']['gameversion']
+ )
+
+ for _, serverdata in servers.items():
+ name = "{0}{1:d}{2:d}".format(serverdata['ip'], serverdata['port'], serverdata['gameid'])
+ serverdata['update'] = serverdata_['u' + name].result()
+
return render_template('server_html.jinja',
servers=servers,
display_time = display_time
diff --git a/static/style.css b/static/style.css
index d27276f..9544769 100644
--- a/static/style.css
+++ b/static/style.css
@@ -183,6 +183,11 @@ div.serverdata {
/* overflow: scroll; */
}
+span.updatemessage {
+ color: red;
+ font-weight: bold;
+}
+
a.servername {
color: lightblue;
font-weight: bold;
diff --git a/templates/server_html.jinja b/templates/server_html.jinja
index 5e38b0a..9702300 100644
--- a/templates/server_html.jinja
+++ b/templates/server_html.jinja
@@ -28,6 +28,9 @@
<li class="servermap">{{ info['data']['map'] }}</li>
<li class="playerinfo">{{ info['data']['players'] }} / {{ info['data']['playersmax'] }}</li>
</ul>
+ {% if info['update']['success'] %}
+ <span class="updatemessage">{{ info['update']['message'] }}</span>
+ {% endif %}
{% if info['data']['players'] %}
<table class="playerlist">