diff options
author | André Glüpker <git@wgmd.de> | 2018-03-30 12:58:27 +0200 |
---|---|---|
committer | André Glüpker <git@wgmd.de> | 2018-03-30 12:59:42 +0200 |
commit | 798aa8ec3d6889faf938cc3316d76a7ef2c6ac41 (patch) | |
tree | c11e8bbfe9ef80ce4822d04d5cc212c0b1b1dd7f | |
parent | 2c07560dab55c4c8e6f9885451488f96c7fc2338 (diff) | |
download | steam-798aa8ec3d6889faf938cc3316d76a7ef2c6ac41.tar.gz steam-798aa8ec3d6889faf938cc3316d76a7ef2c6ac41.tar.bz2 steam-798aa8ec3d6889faf938cc3316d76a7ef2c6ac41.zip |
Query servers in parallel and check for updates
-rwxr-xr-x | main.py | 28 | ||||
-rw-r--r-- | static/style.css | 5 | ||||
-rw-r--r-- | templates/server_html.jinja | 3 |
3 files changed, 34 insertions, 2 deletions
@@ -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"> |