diff --git a/faceitstalker_docker/app/main.py b/faceitstalker_docker/app/main.py index 60a6fdf..5c013b5 100644 --- a/faceitstalker_docker/app/main.py +++ b/faceitstalker_docker/app/main.py @@ -5,49 +5,36 @@ import re import json import xml import xmltodict +import asyncio app = Flask(__name__) - +data_dict = {} @app.route("/", methods=["POST", "GET"]) -def index(): +async def index(): + global data_dict + if request.method == "POST": status_screen = request.form["status_screen_input"] steamids = regex_for_steamids(status_screen) - steamid64_dict = {} - faceit_elo_dict = {} - faceit_level_dict = {} - steam_name_dict = {} - steam_pic_dict = {} - faceit_name_dict = {} - for steamid in steamids: - steamid64_dict[steamid] = steamid_to_64bit(steamid) - faceit_json = get_faceit_data(steamid64_dict[steamid]) - steam_dict = get_steam_data(steamid64_dict[steamid]) - steam_name_dict[steamid] = steam_dict['profile']['steamID'] - steam_pic_dict[steamid] = steam_dict['profile']['avatarFull'] - try: - faceit_elo_dict[steamid] = faceit_json['games']['csgo']['faceit_elo'] - faceit_level_dict[steamid] = faceit_json['games']['csgo']['skill_level'] - faceit_name_dict[steamid] = faceit_json['nickname'] - except: - faceit_elo_dict[steamid] = 0 - faceit_level_dict[steamid] = 0 - faceit_name_dict[steamid] = 0 + data_dict[steamid] = {} + data_dict[steamid]['steamid64'] = steamid_to_64bit(steamid) + + task_get_faceit_data = asyncio.create_task(loop_faceit_data()) + task_get_steam_data = asyncio.create_task(loop_steam_data()) + await task_get_faceit_data + await task_get_steam_data - - - - return render_template('steamids.html', **locals()) + return render_template('steamids.html', data_dict = data_dict) else: return render_template('index.html') @@ -71,20 +58,34 @@ def steamid_to_64bit(steamid): steam64id += 1 return steam64id -def get_steam_data(steamid_64): - steamurl ="https://steamcommunity.com/profiles/" + str(steamid_64) +"/?xml=1" - steam_req = requests.get(steamurl) - steamdict_funct = xmltodict.parse(steam_req.content) - return steamdict_funct -def get_faceit_data(steamid_64): - url = "https://open.faceit.com/data/v4/players?game=csgo&game_player_id=" + str(steamid_64) - headers = { 'accept': 'application/json', 'Authorization' : 'Bearer ab46a7ab-6ab8-4c00-a8ff-41c0ff71d562' } - faceit_response = requests.get(url, headers=headers) - faceit_response_json = faceit_response.json() - return faceit_response_json +async def loop_faceit_data(): + global data_dict + for steamid in data_dict: + url = "https://open.faceit.com/data/v4/players?game=csgo&game_player_id=" + str(data_dict[steamid]['steamid64']) + headers = { 'accept': 'application/json', 'Authorization' : 'Bearer ab46a7ab-6ab8-4c00-a8ff-41c0ff71d562' } + faceit_response = requests.get(url, headers=headers) + faceit_response_json = faceit_response.json() + + + try: + data_dict[steamid]['faceit_elo'] = faceit_response_json['games']['csgo']['faceit_elo'] + data_dict[steamid]['faceit_level'] = faceit_response_json['games']['csgo']['skill_level'] + data_dict[steamid]['faceit_name'] = faceit_response_json['nickname'] + data_dict[steamid]['faceit_acc'] = 'true' + except: + data_dict[steamid]['faceit_acc'] = 'false' +async def loop_steam_data(): + global data_dict + for steamid in data_dict: + steamurl ="https://steamcommunity.com/profiles/" + str(data_dict[steamid]['steamid64']) +"/?xml=1" + steam_req = requests.get(steamurl) + steamdict_funct = xmltodict.parse(steam_req.content) + + data_dict[steamid]['steam_name'] = steamdict_funct['profile']['steamID'] + data_dict[steamid]['steam_pic'] = steamdict_funct['profile']['avatarFull'] @@ -119,6 +120,5 @@ if __name__ == "__main__": - diff --git a/faceitstalker_docker/app/templates/base.html b/faceitstalker_docker/app/templates/base.html index 697c676..b971434 100644 --- a/faceitstalker_docker/app/templates/base.html +++ b/faceitstalker_docker/app/templates/base.html @@ -3,7 +3,7 @@ {% block titel %}{% endblock %} - +