from fpl import FPL from fpl.utils import get_current_gameweek import aiohttp import asyncio class Team: def __init__(self, name): self.name = name def set_players(self, players): self.players = players def show_players_info(self): print(f"{self.name} players:") for p in self.players: print(f"{p} gs = {p.goals_scored} tp = {p.total_points}") total = sum(p.goals_scored for p in self.players) print(f"Total Score => {total}") class SFL: def __init__(self, name): self.name = name async def _setup(self): async with aiohttp.ClientSession() as session: self.session = session self.fpl = FPL(self.session) self.players = await self.fpl.get_players() #return self def setup(self): asyncio.set_event_loop(asyncio.SelectorEventLoop()) asyncio.get_event_loop().run_until_complete(self._setup()) def get_player(self, pid): asyncio.set_event_loop(asyncio.SelectorEventLoop()) return asyncio.get_event_loop().run_until_complete(self._get_player(pid)) async def _get_player(self, pid): return await self.fpl.get_player(pid) def search_player(self, name): results = [{'info': str(x), 'id': x.id } for x in self.players if name in x.web_name.lower()] return results async def main(): async with aiohttp.ClientSession() as session: fpl = FPL(session) gameweek = await fpl.get_gameweek(1) cg = await get_current_gameweek(fpl.session) gameweek2 = await fpl.get_gameweek(cg) gameweek3 = await fpl.get_gameweek(cg+1) players = await fpl.get_players() #print("==== players ====") ''' for p in players[:10]: print(dir(p)) ''' #print(gameweek.name) #print(cg) #print(dir(gameweek)) print(gameweek2) print("======================") #print(gameweek3) team = Team("Tum Team") team.set_players(players[:15]) team.show_players_info() if __name__ == "__main__": asyncio.get_event_loop().run_until_complete(main())