faceitfinder/faceitstalker_docker/app/main.py

147 lines
3.9 KiB
Python

from flask import Flask, render_template, request, redirect, url_for
from waitress import serve
import requests
import re
import json
import xml
import xmltodict
import asyncio
app = Flask(__name__)
@app.route("/", methods=["POST", "GET"])
async def index():
data_dict = {}
if request.method == "POST":
status_screen = request.form["status_screen_input"]
steamids = regex_for_steamids(status_screen)
for steamid in steamids:
data_dict[steamid] = {}
data_dict[steamid]['steamid64'] = steamid_to_64bit(steamid)
task_get_faceit_data = asyncio.create_task(loop_faceit_data(data_dict))
task_get_steam_data = asyncio.create_task(loop_steam_data(data_dict))
faceit_dict = await task_get_faceit_data
steam_dict = await task_get_steam_data
for steamid in faceit_dict:
if faceit_dict[steamid]['faceit_acc'] == 'true' :
data_dict[steamid]['faceit_elo'] = faceit_dict[steamid]['faceit_elo']
data_dict[steamid]['faceit_level'] = faceit_dict[steamid]['faceit_level']
data_dict[steamid]['faceit_name'] = faceit_dict[steamid]['faceit_name']
data_dict[steamid]['faceit_acc'] = faceit_dict[steamid]['faceit_acc']
else:
data_dict[steamid]['faceit_acc'] = faceit_dict[steamid]['faceit_acc']
for steamid in steam_dict:
data_dict[steamid]['steam_name'] = steam_dict[steamid]['steam_name']
data_dict[steamid]['steam_pic'] = steam_dict[steamid]['steam_pic']
return render_template('steamids.html', data_dict = data_dict , steam_dict = steam_dict, faceit_dict = faceit_dict)
else:
return render_template('index.html')
def regex_for_steamids(input_string):
steamids_from_status = re.findall(r"\S*STEAM_+[0-9]+:[0-9]+:[0-9]+", input_string)
return steamids_from_status
def steamid_to_64bit(steamid):
steam64id = 76561197960265728 # Who tf knows how this works
# IT JUST FUCKING DOES!
id_split = steamid.split(":")
steam64id += int(id_split[2]) * 2 # JUST MULTIPLY BY 2... Cause THAT MAKES PERFEKT SENSE RIGHT?!
if id_split[1] == "1":
steam64id += 1
return steam64id
async def loop_faceit_data(data_dict):
faceit_dict = {}
req =requests.Session()
for steamid in data_dict:
faceit_dict[steamid] = {}
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 = req.get(url, headers=headers)
faceit_response_json = faceit_response.json()
try:
faceit_dict[steamid]['faceit_elo'] = faceit_response_json['games']['csgo']['faceit_elo']
faceit_dict[steamid]['faceit_level'] = faceit_response_json['games']['csgo']['skill_level']
faceit_dict[steamid]['faceit_name'] = faceit_response_json['nickname']
faceit_dict[steamid]['faceit_acc'] = 'true'
except:
faceit_dict[steamid]['faceit_acc'] = 'false'
return faceit_dict
async def loop_steam_data(data_dict):
steam_dict = {}
req =requests.Session()
for steamid in data_dict:
steam_dict[steamid] = {}
steamurl ="https://steamcommunity.com/profiles/" + str(data_dict[steamid]['steamid64']) +"/?xml=1"
steam_req = req.get(steamurl)
steamdict_funct = xmltodict.parse(steam_req.content)
steam_dict[steamid]['steam_name'] = steamdict_funct['profile']['steamID']
steam_dict[steamid]['steam_pic'] = steamdict_funct['profile']['avatarFull']
return steam_dict
if __name__ == "__main__":
#app.run(host="127.0.0.1", port=8080, debug=True)
serve(app, host='0.0.0.0', port=8080)