124 lines
2.7 KiB
Python
124 lines
2.7 KiB
Python
from turtle import st
|
|
from flask import Flask, render_template, request, redirect, url_for
|
|
import requests
|
|
import re
|
|
import json
|
|
import xml
|
|
import xmltodict
|
|
|
|
app = Flask(__name__)
|
|
|
|
|
|
|
|
|
|
@app.route("/", methods=["POST", "GET"])
|
|
def index():
|
|
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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return render_template('steamids.html', **locals())
|
|
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
|
|
|
|
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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
app.run(host="127.0.0.1", port=8080, debug=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|