-
Notifications
You must be signed in to change notification settings - Fork 0
/
models.py
43 lines (34 loc) 路 1.37 KB
/
models.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import os
import requests
from dotenv import load_dotenv
load_dotenv()
API_KEY = os.environ.get("API_KEY")
headers = {'TRN-Api-Key': API_KEY}
def process_json_data(data):
platforminfo = data['platformInfo']
stats = data['segments'][0]['stats']
return_dict = {
'avatar_url': platforminfo['avatarUrl'],
'username': platforminfo['platformUserHandle'],
'time_played': stats['timePlayed']['displayValue'],
'kills': stats['kills']['value'],
'deaths': stats['deaths']['value'],
'kd': round(stats['kd']['value'], 2),
'kd_total': round(stats['kd']['value'], 2) + 1.00,
'kd_fraction': round(stats['kd']['value'] / (stats['kd']['value'] + 1.00), 2) * 100,
'wins': stats['wins']['value'],
'losses': stats['losses']['value'],
'headshots': stats['headshots']['value'],
'headshotpct': stats['headshotPct']['value'],
'headshot_percentile': stats['headshotPct']['percentile'],
'kd_percentile': stats['kd']['percentile'],
'wl_percentage': stats['wlPercentage']['value'],
'wl_percentile': stats['wlPercentage']['percentile']
}
return return_dict
def request_tracker_network_api(steam_id=76561199056418213):
resp = requests.get(
url=f"https://public-api.tracker.gg/v2/csgo/standard/profile/steam/{steam_id}",
headers=headers
)
return resp