made async possible

This commit is contained in:
herz 2022-03-15 15:01:36 +01:00
parent a7dda04569
commit 3f1dfd6f94
4 changed files with 71 additions and 69 deletions

View File

@ -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__":

View File

@ -3,7 +3,7 @@
<head>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous">
<title>{% block titel %}{% endblock %}</title>
<link rel="icon" href="/static/Facitstalker-logo.svg" type="image/svg+xml">
<style>
body {
background-color: #212121;
@ -68,7 +68,7 @@
<nav class="navbar navbar-light bg-light">
<div class="container-fluid">
<a class="navbar-brand" href="#">
<img src="/static/logo.png " width="30" height="24">
<img src="/static/Facitstalker-logo.svg " width="50" height="50">
FaceIT Stalker by HerZ
</a>
</div>

View File

@ -2,47 +2,49 @@
{% block titel %}Faceit Elo Search by HerZ{% endblock %}
{% block content %}
<div class="input-group">
{%for steamid in steamids%}
{%for steamid in data_dict%}
<div class="card" >
<img class="Steam-PB" src="{{steam_pic_dict[steamid]}}" alt="Card image cap">
<img class="Steam-PB" src="{{data_dict[steamid]['steam_pic']}}" alt="Card image cap">
<div class="card-body">
<h3 class="STeam-Name">{{steam_name_dict[steamid]}}</h3>
<h3 class="STeam-Name">{{data_dict[steamid]['steam_name']}}</h3>
<p class="FaceIT-IMG">
{% if faceit_level_dict[steamid] == 1 %}
<img src="/static/faceit1.svg" alt="FaceIT Level 1" width="100" height="100">
{% elif faceit_level_dict[steamid] == 2 %}
<img src="/static/faceit2.svg" alt="FaceIT Level 2" width="100" height="100">
{% elif faceit_level_dict[steamid] == 3 %}
<img src="/static/faceit3.svg" alt="FaceIT Level 3" width="100" height="100">
{% elif faceit_level_dict[steamid] == 4 %}
<img src="/static/faceit4.svg" alt="FaceIT Level 4" width="100" height="100">
{% elif faceit_level_dict[steamid] == 5 %}
<img src="/static/faceit5.svg" alt="FaceIT Level 5" width="100" height="100">
{% elif faceit_level_dict[steamid] == 6 %}
<img src="/static/faceit6.svg" alt="FaceIT Level 6" width="100" height="100">
{% elif faceit_level_dict[steamid] == 7 %}
<img src="/static/faceit7.svg" alt="FaceIT Level 7" width="100" height="100">
{% elif faceit_level_dict[steamid] == 8 %}
<img src="/static/faceit8.svg" alt="FaceIT Level 8" width="100" height="100">
{% elif faceit_level_dict[steamid] == 9 %}
<img src="/static/faceit9.svg" alt="FaceIT Level 9" width="100" height="100">
{% elif faceit_level_dict[steamid] == 10 %}
<img src="/static/faceit10.svg" alt="FaceIT Level 10" width="100" height="100">
{% if data_dict[steamid]['faceit_acc'] == 'true' %}
{% if data_dict[steamid]['faceit_level'] == 1 %}
<img src="/static/faceit1.svg" alt="FaceIT Level 1" width="100" height="100">
{% elif data_dict[steamid]['faceit_level'] == 2 %}
<img src="/static/faceit2.svg" alt="FaceIT Level 2" width="100" height="100">
{% elif data_dict[steamid]['faceit_level'] == 3 %}
<img src="/static/faceit3.svg" alt="FaceIT Level 3" width="100" height="100">
{% elif data_dict[steamid]['faceit_level'] == 4 %}
<img src="/static/faceit4.svg" alt="FaceIT Level 4" width="100" height="100">
{% elif data_dict[steamid]['faceit_level'] == 5 %}
<img src="/static/faceit5.svg" alt="FaceIT Level 5" width="100" height="100">
{% elif data_dict[steamid]['faceit_level'] == 6 %}
<img src="/static/faceit6.svg" alt="FaceIT Level 6" width="100" height="100">
{% elif data_dict[steamid]['faceit_level'] == 7 %}
<img src="/static/faceit7.svg" alt="FaceIT Level 7" width="100" height="100">
{% elif data_dict[steamid]['faceit_level'] == 8 %}
<img src="/static/faceit8.svg" alt="FaceIT Level 8" width="100" height="100">
{% elif data_dict[steamid]['faceit_level'] == 9 %}
<img src="/static/faceit9.svg" alt="FaceIT Level 9" width="100" height="100">
{% elif data_dict[steamid]['faceit_level'] == 10 %}
<img src="/static/faceit10.svg" alt="FaceIT Level 10" width="100" height="100">
{% endif %}
{% else %}
<p>No FaceIT Account Found.</p>
{% endif %}
</p>
</div>
{% if not faceit_elo_dict[steamid] == 0 %}
{% if data_dict[steamid]['faceit_acc'] == 'true' %}
<div class="Faceit-elo-and-steamid64">
<p class="FaceIT-elo">FaceIT ELO: {{faceit_elo_dict[steamid]}}</p>
<p class="SteamID64">SteamID: {{steamid64_dict[steamid]}}</p>
<p class="FaceIT-elo">FaceIT ELO: {{data_dict[steamid]['faceit_elo']}}</p>
<p class="SteamID64">SteamID: {{data_dict[steamid]['steamid64']}}</p>
</div>
{% endif %}
<div class="profile-links">
<a href="https://steamcommunity.com/profiles/{{steamid64_dict[steamid]}}" class="card-link">Steam Profile</a>
{% if not faceit_elo_dict[steamid] == 0 %}
<a href="https://www.faceit.com/en/players/{{faceit_name_dict[steamid]}}" class="card-link">FaceIT Link</a>
<a href="https://steamcommunity.com/profiles/{{data_dict[steamid]['steamid64']}}" class="card-link">Steam Profile</a>
{% if data_dict[steamid]['faceit_acc'] == 'true' %}
<a href="https://www.faceit.com/en/players/{{data_dict[steamid]['faceit_name']}}" class="card-link">FaceIT Link</a>
{% endif %}
</div>
</div>