-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.py
94 lines (80 loc) · 3.31 KB
/
script.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
89
90
91
92
93
94
import requests
import json
import random
from datetime import datetime
import os
SECRET = os.environ['ENV_SECRET']
def get_fortnite_data(api_key):
url = "https://fortniteapi.io/v1/stats?account=5afc257cdbf8408ebebcf241a681a1e9"
headers = {
"Authorization": api_key,
"Content-Type": "application/json"
}
try:
response = requests.get(url, headers=headers)
response.raise_for_status()
data = response.json()
return data
except requests.exceptions.RequestException as e:
print("Error connecting to the API:", e)
return None
def main():
api_key = SECRET
# Fetch Fortnite data
api_response = get_fortnite_data(api_key)
if api_response:
# Calculate & store top level stats for processing in HTML
level = api_response["account"]["level"]
top1_sum = sum([mode_stats["placetop1"] for mode_stats in api_response["global_stats"].values()])
kd_average = round(sum([mode_stats["kd"] for mode_stats in api_response["global_stats"].values()]) / len(api_response["global_stats"]), 2)
winrate_average = round((sum([mode_stats["winrate"] for mode_stats in api_response["global_stats"].values()]) / len(api_response["global_stats"])) * 100, 2)
kills_sum = sum([mode_stats["kills"] for mode_stats in api_response["global_stats"].values()])
# Additional processing with api_response
# Return all variables
return level, top1_sum, kd_average, winrate_average, kills_sum
else:
print("Failed to fetch Fortnite data.")
return None, None, None, None, None
if __name__ == "__main__":
level, top1_sum, kd_average, winrate_average, kills_sum = main()
if level is not None:
print("Level value:", level)
print("Sum of all 'placetop1':", top1_sum)
print("Average of all 'kd':", kd_average)
print("Average of all 'winrate':", winrate_average)
print("Sum of all 'kills':", kills_sum)
else:
print("Failed to retrieve Fortnite data.")
skin = (random.randint(1, 20))
# Get todays date & format as string
today = datetime.today()
date = today.strftime("%A %d %B %Y")
html = """\
<html>
<head>
<link rel="stylesheet" href="fortnite.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.1/css/all.min.css">
</head>
<body>
<div class="card">
<div class="layered-image">
<img class="image-base" src="images/background.avif" alt="" style="width:100%"/>
<img class="image-overlay" src="images/{skin}.png" alt="IronVogel" style="width:100%"/>
</div>
<h1>IronVogel</h1>
<p class="title"><i class="fab fa-playstation" ></i> Current Level - {level}</p>
<div style="margin: 24px 0; color: lightslategrey;">
<p><i class="fas fa-trophy"></i> {top1_sum} Victories</p>
<p><i class="fas fa-star-half-alt"></i> {winrate_average} % Win Ratio</p>
<p><i class="fas fa-tachometer-alt"></i> {kd_average} K/D Ratio</p>
<p><i class="fas fa-skull-crossbones"></i> {kills_sum} Kills</p>
</div>
<p><small><small><small>Updated {date}<small><small><small></p>
<p><button onclick="document.location='https://fortnitetracker.com/profile/all/IronVogel'">Detailed Stats</button></p>
</div>
</body>
</html>
""".format(**locals())
# Output to HTML file
with open("fortnite.html", "w") as file:
file.write(html)