-
Notifications
You must be signed in to change notification settings - Fork 1
/
stats.py
88 lines (60 loc) · 3.48 KB
/
stats.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
import requests
import json
from TOK import TokenFortniteStat
token = TokenFortniteStat
URLFORTNITE = "https://api.fortnitetracker.com/v1/store"
def get_value(listOfDicts, key):
for subVal in listOfDicts:
if subVal["key"] == key:
return subVal["value"]
class stat:
def __init__(self):
pass
def getPlayerId(self,player,plateform):
r = requests.get(url = f"https://api.fortnitetracker.com/v1/profile/{plateform}/{player}/", headers = {"TRN-Api-Key" : token})
txt = json.loads(r.text)
return(txt["accountId"])
def player(self,player,plateform,actual):
print(f"https://api.fortnitetracker.com/v1/profile/{plateform}/{player}/")
r = requests.get(url = f"https://api.fortnitetracker.com/v1/profile/{plateform}/{player}/", headers = {"TRN-Api-Key" : token})
#print(r)
if "It's not you, it's us. We had an error. These things happen. If it keeps happening, please" in r.text :
return("On dirait que vous n'etes pas dans fortnite tracker ou que vous avez mal tapé votre pseudo, essayez directement depuis leur site : https://fortnitetracker.com/")
elif "40" in r:
return("Les services de Fortnite Tracker sont inatteignable")
else:
with open("test.html", "w", encoding = "utf-8") as f:
f.write(r.text)
txt = json.loads(r.text)
if actual :
kills = txt['stats']['curr_p2']['kills']['valueInt'] + txt['stats']['curr_p10']['kills']['valueInt']+txt['stats']['curr_p9']['kills']['valueInt']
matches = txt['stats']['curr_p2']['matches']['valueInt'] + txt['stats']['curr_p10']['matches']['valueInt']+txt['stats']['curr_p9']['matches']['valueInt']
KD = round(kills/matches,2)
wins = txt['stats']['curr_p2']['top1']['valueInt'] + txt['stats']['curr_p10']['top1']['valueInt']+txt['stats']['curr_p9']['top1']['valueInt']
ret = f"""Pseudo : {player}
Nombre de top1 cette saison : {wins}
Nombre de kills cette saison : {kills}
Kd cette saison : {KD}
Nombre de top 1 en solo cette saison : {txt['stats']['curr_p2']['top1']['value']}
Kd en solo cette saison : {txt['stats']['curr_p2']['kd']['value']}
Nombre de top 1 en duo cette saison : {txt['stats']['curr_p10']['top1']['value']}
Kd en duo cette saison : {txt['stats']['curr_p10']['kd']['value']}
Nombre de top 1 en squad cette saison : {txt['stats']['curr_p9']['top1']['value']}
Kd en squad cette saison : {txt['stats']['curr_p9']['kd']['value']}"""
else:
ret = f"""Pseudo : {player}
Nombre de top 1 totals: {get_value(txt['lifeTimeStats'], 'Wins')}
Nombre de kills totals : {get_value(txt['lifeTimeStats'], 'Kills')}
KD : {get_value(txt['lifeTimeStats'], 'K/d')}
Nombre de top 1 en solo over all : {txt['stats']['p2']['top1']['value']}
Kd en solo over all : {txt['stats']['p2']['kd']['value']}
Nombre de top 1 en duo over all : {txt['stats']['p10']['top1']['value']}
Kd en duo over all : {txt['stats']['p10']['kd']['value']}
Nombre de top 1 en squad over all : {txt['stats']['p9']['top1']['value']}
Kd en squad over all : {txt['stats']['p9']['kd']['value']}"""
print(ret)
return(ret)
def lastGame(self,player):
r = requests.get(url = f"GET https://api.fortnitetracker.com/v1/profile/account/{self.getPlayerId(player,'pc')}/matches/", headers = {"TRN-Api-Key" : token})
with open("historic.html", "w", encoding = "utf-8") as f:
f.write(r.text)