-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathutils.py
More file actions
52 lines (43 loc) · 1.33 KB
/
utils.py
File metadata and controls
52 lines (43 loc) · 1.33 KB
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
import asyncio
headers = {"User-Agent": ""}
async def fetch(session, url, retries=5, cooldown=1):
retries_count = 0
while True:
async with session.get(url, headers=headers, raise_for_status=True) as response:
result = await response.json()
return result
retries_count += 1
if retries_count > retries:
raise Exception(f"Could not fetch {url} after {retries} retries")
if cooldown:
await asyncio.sleep(cooldown)
def position_converter(position):
"""Converts a player's `element_type` to their actual position."""
position_map = {1: "Goalkeeper", 2: "Defender", 3: "Midfielder", 4: "Forward"}
return position_map[position]
def team_converter(team_id):
"""Converts a team's ID to their actual name."""
team_map = {
1: "Arsenal",
2: "Aston Villa",
3: "Brighton",
4: "Burnley",
5: "Chelsea",
6: "Crystal Palace",
7: "Everton",
8: "Fulham",
9: "Leicester",
10: "Leeds",
11: "Liverpool",
12: "Man City",
13: "Man Utd",
14: "Newcastle",
15: "Sheffield Utd",
16: "Southampton",
17: "Spurs",
18: "West Brom",
19: "West Ham",
20: "Wolves",
None: None,
}
return team_map[team_id]