|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+from fpl import FPL
|
|
|
2
|
+from fpl.utils import get_current_gameweek
|
|
|
3
|
+import aiohttp
|
|
|
4
|
+import asyncio
|
|
|
5
|
+
|
|
|
6
|
+class Team:
|
|
|
7
|
+ def __init__(self, name):
|
|
|
8
|
+ self.name = name
|
|
|
9
|
+
|
|
|
10
|
+ def set_players(self, players):
|
|
|
11
|
+ self.players = players
|
|
|
12
|
+
|
|
|
13
|
+ def show_players_info(self):
|
|
|
14
|
+ print(f"{self.name} players:")
|
|
|
15
|
+ for p in self.players:
|
|
|
16
|
+ print(f"{p} gs = {p.goals_scored} tp = {p.total_points}")
|
|
|
17
|
+
|
|
|
18
|
+ total = sum(p.goals_scored for p in self.players)
|
|
|
19
|
+ print(f"Total Score => {total}")
|
|
|
20
|
+
|
|
|
21
|
+class SFL:
|
|
|
22
|
+ def __init__(self, name):
|
|
|
23
|
+ self.name = name
|
|
|
24
|
+
|
|
|
25
|
+ async def _setup(self):
|
|
|
26
|
+ async with aiohttp.ClientSession() as session:
|
|
|
27
|
+ self.session = session
|
|
|
28
|
+ self.fpl = FPL(self.session)
|
|
|
29
|
+ self.players = await self.fpl.get_players()
|
|
|
30
|
+ #return self
|
|
|
31
|
+
|
|
|
32
|
+ def setup(self):
|
|
|
33
|
+ asyncio.set_event_loop(asyncio.SelectorEventLoop())
|
|
|
34
|
+ asyncio.get_event_loop().run_until_complete(self._setup())
|
|
|
35
|
+
|
|
|
36
|
+ def get_player(self, pid):
|
|
|
37
|
+ asyncio.set_event_loop(asyncio.SelectorEventLoop())
|
|
|
38
|
+ return asyncio.get_event_loop().run_until_complete(self._get_player(pid))
|
|
|
39
|
+
|
|
|
40
|
+ async def _get_player(self, pid):
|
|
|
41
|
+ return await self.fpl.get_player(pid)
|
|
|
42
|
+
|
|
|
43
|
+
|
|
|
44
|
+async def main():
|
|
|
45
|
+ async with aiohttp.ClientSession() as session:
|
|
|
46
|
+ fpl = FPL(session)
|
|
|
47
|
+ gameweek = await fpl.get_gameweek(1)
|
|
|
48
|
+
|
|
|
49
|
+ cg = await get_current_gameweek(fpl.session)
|
|
|
50
|
+ gameweek2 = await fpl.get_gameweek(cg)
|
|
|
51
|
+ gameweek3 = await fpl.get_gameweek(cg+1)
|
|
|
52
|
+
|
|
|
53
|
+ players = await fpl.get_players()
|
|
|
54
|
+
|
|
|
55
|
+ #print("==== players ====")
|
|
|
56
|
+ '''
|
|
|
57
|
+ for p in players[:10]:
|
|
|
58
|
+ print(dir(p))
|
|
|
59
|
+ '''
|
|
|
60
|
+
|
|
|
61
|
+
|
|
|
62
|
+ #print(gameweek.name)
|
|
|
63
|
+ #print(cg)
|
|
|
64
|
+ #print(dir(gameweek))
|
|
|
65
|
+ print(gameweek2)
|
|
|
66
|
+ print("======================")
|
|
|
67
|
+ #print(gameweek3)
|
|
|
68
|
+
|
|
|
69
|
+ team = Team("Tum Team")
|
|
|
70
|
+ team.set_players(players[:15])
|
|
|
71
|
+ team.show_players_info()
|
|
|
72
|
+
|
|
|
73
|
+if __name__ == "__main__":
|
|
|
74
|
+ asyncio.get_event_loop().run_until_complete(main())
|