Nenhuma Descrição

fpl_lib.py 2.1KB

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