@@ -59,24 +59,27 @@ def __init__(self, api) -> None:
59
59
self .full_sport = self .api ['Sport' ]
60
60
self .sport = [* self .full_sport ]
61
61
self .main_sport = self .full_sport [self .sport [0 ]]
62
- if 'standings' in self .main_sport :
63
- self .standings = self .build_standings ()
64
- self ._length = len (self .standings )
65
- self ._positions = [(team .get ('name' ), team .get ('position' )) for team in self .standings ]
66
- self ._leagues = [(team .get ('name' ), team .get ('league' )) for team in self .standings ]
67
- self ._games_played = [(team .get ('name' ), team .get ('games' ).get ('played' )) for team in self .standings ]
68
- self ._wins = [(team .get ('name' ), team ['games' ]['win' ]['total' ]) for team in self .standings ]
69
- self ._wins_percentage = [(team .get ('name' ), team ['games' ]['win' ]['percentage' ]) for team in self .standings ]
70
- self ._losses = [(team .get ('name' ), team ['games' ]['lose' ]['total' ]) for team in self .standings ]
71
- self ._loss_percentage = [(team .get ('name' ), team ['games' ]['lose' ]['percentage' ]) for team in self .standings ]
72
- if 'next_game' in self .main_sport :
73
- self .next_game = self .build_nextgame ()
74
- self ._game_ids = [game .get ('game_id' ) for game in self .next_game ]
75
- self ._timestamps = [(game .get ('game_id' ), game .get ('timestamp' )) for game in self .next_game ]
76
- self ._teams = [(game .get ('game_id' ), game .get ('teams' )) for game in self .next_game ]
77
- self ._vs = [(game .get ('game_id' ), (game ['teams' ]['home' ]['name' ], game ['teams' ]['away' ]['name' ])) for game in self .next_game ]
78
- self ._status = [(game .get ('game_id' ), game .get ('status' )) for game in self .next_game ]
79
- self ._game_result = {game .get ('game_id' ): game .get ('score' ) for game in self .next_game }
62
+ if len (self .main_sport ['standings' ]['errors' ]) != 0 :
63
+ self ._error = self .get_error
64
+ else :
65
+ if 'standings' in self .main_sport :
66
+ self .standings = self .build_standings ()
67
+ self ._length = len (self .standings )
68
+ self ._positions = [(team .get ('name' ), team .get ('position' )) for team in self .standings ]
69
+ self ._leagues = [(team .get ('name' ), team .get ('league' )) for team in self .standings ]
70
+ self ._games_played = [(team .get ('name' ), team .get ('games' ).get ('played' )) for team in self .standings ]
71
+ self ._wins = [(team .get ('name' ), team ['games' ]['win' ]['total' ]) for team in self .standings ]
72
+ self ._wins_percentage = [(team .get ('name' ), team ['games' ]['win' ]['percentage' ]) for team in self .standings ]
73
+ self ._losses = [(team .get ('name' ), team ['games' ]['lose' ]['total' ]) for team in self .standings ]
74
+ self ._loss_percentage = [(team .get ('name' ), team ['games' ]['lose' ]['percentage' ]) for team in self .standings ]
75
+ if 'next_game' in self .main_sport :
76
+ self .next_game = self .build_nextgame ()
77
+ self ._game_ids = [game .get ('game_id' ) for game in self .next_game ]
78
+ self ._timestamps = [(game .get ('game_id' ), game .get ('timestamp' )) for game in self .next_game ]
79
+ self ._teams = [(game .get ('game_id' ), game .get ('teams' )) for game in self .next_game ]
80
+ self ._vs = [(game .get ('game_id' ), (game ['teams' ]['home' ]['name' ], game ['teams' ]['away' ]['name' ])) for game in self .next_game ]
81
+ self ._status = [(game .get ('game_id' ), game .get ('status' )) for game in self .next_game ]
82
+ self ._game_result = {game .get ('game_id' ): game .get ('score' ) for game in self .next_game }
80
83
def __repr__ (self ):
81
84
attrs = [
82
85
f"length={ self ._length } " ,
@@ -96,7 +99,7 @@ def __repr__(self):
96
99
]
97
100
joined = "\t \n " .join (attrs )
98
101
return f"Sport(\n { joined } )"
99
-
102
+
100
103
def build_standings (self ):
101
104
#counter = 0
102
105
position = []
@@ -129,6 +132,13 @@ def build_nextgame(self):
129
132
})
130
133
return main
131
134
135
+ @property
136
+ def get_error (self ):
137
+ if isinstance (self .main_sport ['standings' ]['errors' ], list ):
138
+ return True , ""
139
+ else :
140
+ return False , self .main_sport ['standings' ]['errors' ]['requests' ]
141
+
132
142
@property
133
143
def get_length_position_teams (self ):
134
144
return len (self .standings )
0 commit comments