-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfootball.py
1701 lines (1450 loc) · 67 KB
/
football.py
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
"""SportMonks Football API"""
import os
import logging
from typing import Dict, Optional, Union, List, Any
import numpy as np
import pandas as pd
from base import BaseAPI
import helper
from errors import IncompatibleArgs, NotJSONNormalizable
log = helper.setup_logger(__name__, "SM_API.log")
KEY = os.environ.get("SPORTMONKS_KEY")
class Continents(BaseAPI):
"""Continents Class."""
def __init__(self, api_key: Optional[str] = None, timeout: Optional[int] = None):
super().__init__(api_key, timeout)
def continents(self, continent_id: Optional[int] = None,
includes: Optional[Union[str, List[str]]] = None,
filters: Optional[dict] = None, df: bool = False,
df_cols: Optional[Union[str, List[str]]] = None):
"""
The leagues endpoint helps you with assigning Countries and Leagues
to the part of the world (Continent) they belong to.
Available leagues are Europe, Asia, Africa, Oceania,
North America and South America.
Args:
continent_id:
id of the continent you want to retrieve.
If no continent_id is specified, all leagues will be returned.
df:
if you want it in a Pandas DataFrame (if possible).
includes:
Possible includes: countries.
***See Sportmonks.com for information regarding includes.
Returns:
Parsed HTTP response from SportMonks API.
JSON format.
"""
if continent_id:
log.info("Get continent by id: %s, with includes = %s", continent_id, includes)
continents = self.make_request(endpoint=["continents", continent_id],
includes=includes, filters=filters)
if df:
try:
df_continents = self._to_df(continents, cols=df_cols)
return df_continents
except NotJSONNormalizable:
log.info("Not JSON-normalizable, returning JSON instead.")
return continents
else:
return continents
else:
log.info("Get all continents")
continents = self.make_request(endpoint="continents", includes=includes)
if df:
try:
continents = self._to_df(continents, cols=df_cols)
return continents
except NotJSONNormalizable:
log.info("Not JSON-normalizable, returning JSON instead.")
return continents
else:
return continents
log.info("Returned %s leagues with includes = %s", len(continents), includes)
class Countries(BaseAPI):
"""Countries Class"""
def __init__(self, api_key: Optional[str] = None, timeout: Optional[int] = None):
super().__init__(api_key, timeout)
def countries(self, country_id: Optional[int] = None,
includes: Optional[Union[str, List[str]]] = None,
filters: Optional[dict] = None, df: bool = False,
df_cols: Optional[Union[str, List[str]]] = None):
"""
The Countries endpoint provides you Country information
like for example its Flag, IsoCode, Continent and other related Country information.
If no country id is specified, all countries will be returned
Args:
country_id:
id of the country you want to retrieve.
If no country_id is specified, all countries will be returned.
includes:
Possible includes: leagues, continent.
***See Sportmonks.com for information regarding includes.
Returns:
Parsed HTTP response from SportMonks API.
JSON format.
"""
if country_id:
log.info("Returning country by id: %s, with includes = %s", country_id, includes)
countries = self.make_request(endpoint=["countries", country_id],
includes=includes, filters=filters)
if df:
try:
df_countries = self._to_df(countries, cols=df_cols)
return df_countries
except NotJSONNormalizable:
log.info("Not JSON-noralizable, returning JSON instead.")
return countries
else:
return countries
else:
log.info("Returning all countries")
countries = self.make_request(endpoint="countries", includes=includes)
if df:
try:
df_countries = self._to_df(countries, cols=df_cols)
return df_countries
except NotJSONNormalizable:
log.info("Not JSON-normalizable, returning JSON instead.")
return countries
else:
return countries
class Leagues(BaseAPI):
"""Leagues Class"""
def __init__(self, api_key: Optional[str] = None, timeout: Optional[int] = None):
super().__init__(api_key, timeout)
def by_id(self, league_id: Optional[int] = None,
includes: Optional[Union[str, List[str]]] = None,
filters: Optional[dict] = None, df: bool = False,
df_cols: Optional[Union[str, List[str]]] = None):
"""
A request on this endpoint would return a response with all Leagues you have access to,
based on the plan you are subscribed to. The Leagues endpoint provides you
League information like its ID, Name, Country, Coverage etc.
If no league id is specified, all leagues in your plan will be returned
Args:
league_id:
id of the league you want to retrieve.
If no league_id is specified, all leagues in your plan will be returned.
includes:
Possible includes: country, season, seasons.
***See Sportmonks.com for information regarding includes.
Returns:
Parsed HTTP response from SportMonks API.
JSON format.
"""
if league_id:
log.info("Return a league by id: %s, with includes = %s", league_id, includes)
leagues = self.make_request(endpoint=["leagues", league_id],
includes=includes, filters=filters)
if df:
try:
df_leagues = self._to_df(leagues, cols=df_cols)
return df_leagues
except NotJSONNormalizable:
log.info("Not JSON-normalizable; returning JSON instead.")
return leagues
else:
return leagues
else:
log.info("Returning all leagues")
leagues = self.make_request(endpoint="leagues", includes=includes)
if df:
try:
df_leagues = self._to_df(leagues, cols=df_cols)
return df_leagues
except NotJSONNormalizable:
log.info("Not JSON-normalizable; returning JSON instead.")
return leagues
else:
return leagues
def by_name(self, search: str, includes: Optional[Union[str, List[str]]] = None,
filters: Optional[dict] = None, df: bool = False,
df_cols: Optional[Union[str, List[str]]] = None):
"""
A request on this endpoint would return a response with all Leagues you have access to,
based on the plan you are subscribed to. The Leagues endpoint provides you
League information like its ID, Name, Country, Coverage etc.
If no league id is specified, all leagues in your plan will be returned
Args:
name:
name of the league
includes:
Possible includes: country, season, seasons.
***See Sportmonks.com for information regarding includes.
Returns:
Parsed HTTP response from SportMonks API.
JSON format.
"""
log.info("Returning a league by search: %s", search)
leagues = self.make_request(endpoint=["leagues", "search", search],
includes=includes, filters=filters)
if df:
try:
df_leagues = self._to_df(leagues, cols=df_cols)
return df_leagues
except NotJSONNormalizable:
log.info("Not JSON-normalizable; returning JSON.")
return leagues
else:
return leagues
class Seasons(BaseAPI):
"""Seasons API"""
def __init__(self, api_key: Optional[str] = None, timeout: Optional[int] = None):
super().__init__(api_key, timeout)
def seasons(self, season_id: Optional[int] = None,
includes: Optional[Union[str, List[str]]] = None,
filters: Optional[dict] = None, df: bool = False,
df_cols: Optional[Union[str, List[str]]] = None):
"""
Responses of the Seasons endpoint are limited to Seasons of the Leagues available in the
Plan you are subscribed to.
Responses provide you details about for example the Season ID, Name, League ID, Year and
if the Season is Active Yes or No.
If no season id is specified, all seasons will be returned
Possible includes: league, stages, rounds, upcoming, results,
groups, goalscorers, cardscorers,assistscorers,
aggregatedGoalscorers, aggregatedCardscorers, aggregatedAssistscorers, fixtures
+ stage, round IF season_id SPECIFIED
Args:
season_id: optional
id of the season you want to retrieve.
If no season id is specified, all seasons will be returned.
includes: optional
Possible includes: league, stages, rounds, upcoming, results,
groups, goalscorers, cardscorers,assistscorers, aggregatedGoalscorers,
aggregatedCardscorers, aggregatedAssistscorers, fixtures
+ stage, round IF season_id is specified.
***See Sportmonks.com for information regarding includes.
Returns:
Parsed HTTP response from SportMonks API.
JSON format.
"""
if season_id:
log.info("Returning season by id: %s, with includes = %s", season_id, includes)
seasons = self.make_request(endpoint=["seasons", season_id],
includes=includes, filters=filters)
if df:
try:
df_seasons = self._to_df(seasons, cols=df_cols)
return df_seasons
except NotJSONNormalizable:
log.info("Not JSON-normalizable; returning JSON instead.")
return seasons
else:
return seasons
else:
log.info("Returning all seasons")
seasons = self.make_request(endpoint="seasons", includes=includes)
if df:
try:
df_seasons = self._to_df(seasons, cols=df_cols)
except NotJSONNormalizable:
log.info("Not JSON-normalizable; returning JSON instead.")
return seasons
else:
return seasons
class Bookmakers(BaseAPI):
"""Bookmakers Class"""
def __init__(self, api_key: Optional[str] = None, timeout: Optional[int] = None):
super().__init__(api_key, timeout)
def bookmakers(self, bookmaker_id: Optional[int] = None,
filters: Optional[dict] = None, df: bool = False,
df_cols: Optional[Union[str, List[str]]] = None):
"""
Return a bookmaker by id.
***NO INCLUDES AVAILABLE FOR THIS ENDPOINT
Args:
bookmaker_id: optional
id of the bookmaker you want to retrieve.
If no bookmaker_id is specified, then all will be returned.
Returns:
Parsed HTTP response from SportMonks API.
JSON format.
"""
if bookmaker_id:
log.info("Returning bookmaker by id: %s", bookmaker_id)
bookmakers = self.make_request(endpoint=["bookmakers", bookmaker_id], filters=filters)
if df:
try:
df_bookmakers = self._to_df(bookmakers, cols=df_cols)
return df_bookmakers
except NotJSONNormalizable:
log.info("Not JSON-normalizable, returning JSON.")
return bookmakers
else:
return bookmakers
else:
log.info("Returning all bookmakers")
bookmakers = self.make_request(endpoint="bookmakers")
if df:
try:
df_bookmakers = self._to_df(bookmakers, cols=df_cols)
return df_bookmakers
except NotJSONNormalizable:
log.info("Not JSON-normalizable, returning JSON.")
return bookmakers
else:
return bookmakers
class Markets(BaseAPI):
"""Markets Class"""
def __init__(self, api_key: Optional[str] = None, timeout: Optional[int] = None):
super().__init__(api_key, timeout)
def markets(self, market_id: Optional[int] = None,
filters: Optional[dict] = None, df: bool = False,
df_cols: Optional[Union[str, List[str]]] = None):
"""
Markets represent the betting options available per bookmaker.
***NO INCLUDES AVAILABLE FOR THIS ENDPOINT
Args:
market_id:
id of the market you want to return.
If no market_id is specified, all markets will be returned.
Returns:
Parsed HTTP response from SportMonks API.
JSON format.
"""
if market_id:
log.info("Returning market: %s", market_id)
markets = self.make_request(endpoint=["markets", market_id], filters=filters)
if df:
try:
df_markets = self._to_df(markets, cols=df_cols)
return df_markets
except NotJSONNormalizable:
log.info("Not JSON-normalizable, returning JSON")
return markets
else:
return markets
else:
markets = self.make_request(endpoint="markets")
log.info("Returning all markets; %s markets", len(markets))
if df:
try:
df_markets = self._to_df(markets, cols=df_cols)
return df_markets
except NotJSONNormalizable:
log.info("Not JSON-normalizable, returning JSON")
return markets
else:
return markets
class Teams(BaseAPI):
"""Teams Class"""
def __init__(self, api_key: Optional[str] = None, timeout: Optional[int] = None):
super().__init__(api_key, timeout)
def by_id(self, team_id: int, includes: Optional[Union[str, List[str]]] = None,
filters: Optional[dict] = None, df: bool = False,
df_cols: Optional[Union[str, List[str]]] = None):
"""
With the Teams endpoint you can find all Team Details you need.
You can think of information about when the Team is founded, Logo, Team Name,
Short Name etc.
Args:
team_id:
id of the team you want to return.
includes:
Possible includes: country, squad, coach, transfers, sidelined,
stats, venue, fifaranking, uefaranking, visitorFixtures, localFixtures,
visitorResults, latest, upcoming, goalscorers,
cardscorers, assistscorers, aggregatedGoalscorers, aggregatedCardscorers,
aggregatedAssistscorers, league, activeSeasons, trophies.
***See Sportmonks.com for information regarding includes.
Returns:
Parsed HTTP response from SportMonks API.
JSON format.
"""
team = self.make_request(endpoint=["teams", team_id], includes=includes, filters=filters)
if df:
try:
df_team = self._to_df(team, cols=df_cols)
return df_team
except NotJSONNormalizable:
log.info("Not JSON-normalizable, returning JSON.")
return team
else:
return team
def by_season_id(self, season_id: int, includes: Optional[Union[str, List[str]]] = None,
filters: Optional[dict] = None, df: bool = False,
df_cols: Optional[Union[str, List[str]]] = None):
"""
With the Teams endpoint you can find all Team Details you need.
You can think of information about when the Team is founded, Logo, Team Name,
Short Name etc.
Args:
season:
id of the season you want to return.
includes:
Possible includes: country, squad, coach, transfers, sidelined,
stats, venue, fifaranking,uefaranking, visitorFixtures, localFixtures,
visitorResults, latest, upcoming, goalscorers,
cardscorers, assistscorers, aggregatedGoalscorers, aggregatedCardscorers,
aggregatedAssistscorers, league, activeSeasons, trophies.
***See Sportmonks.com for information regarding includes.
Returns:
Parsed HTTP response from SportMonks API.
JSON format.
"""
teams = self.make_request(endpoint=["teams", "season", season_id],
includes=includes, filters=filters)
if df:
try:
df_teams = self._to_df(teams, cols=df_cols)
return df_teams
except NotJSONNormalizable:
log.info("Not JSON-normalizable, returning JSON.")
return teams
else:
return teams
def team_current_leagues(self, team_id: int, filters: Optional[dict] = None,
df: bool = False, df_cols: Optional[Union[str, List[str]]] = None):
"""
Return all current leagues for a given team.
***NO INCLUDES AVAILABLE FOR THIS ENDPOINT
Args:
team_id:
id of the team.
Returns:
Parsed HTTP response from SportMonks API.
JSON format.
"""
current_leagues = self.make_request(endpoint=["teams", team_id, "current"], filters=filters)
if df:
try:
df_current_leagues = self._to_df(current_leagues, cols=df_cols)
return df_current_leagues
except NotJSONNormalizable:
log.info("Not JSON-normalizable, returning JSON.")
return current_leagues
else:
return current_leagues
def team_historic_leagues(self, team_id, filters: Optional[dict] = None,
df: bool = False, df_cols: Optional[Union[str, List[str]]] = None):
"""
Return all historic leagues for a given team.
***NO INCLUDES AVAILABLE FOR THIS ENDPOINT
Args:
team_id:
id of the team
Returns:
Parsed HTTP response from SportMonks API.
JSON format.
"""
historic_leagues = self.make_request(endpoint=["teams", team_id, "history"],
filters=filters)
if df:
try:
df_historic_leagues = self._to_df(historic_leagues, cols=df_cols)
return df_historic_leagues
except NotJSONNormalizable:
log.info("Not JSON-normalizable, returning JSON.")
return historic_leagues
else:
return historic_leagues
def squads(self, season_id: int, team_id: int,
includes: Optional[Union[str, List[str]]] = None,
filters: Optional[dict] = None,
df: bool = False, df_cols: Optional[Union[str, List[str]]] = None):
"""
Since November 2017 we offer the ability to load historical Squads.
This means you can retrieveSquads from 2005 onwards, including
Player performance of those Games of the requested Season.
The squad include on any team related endpoint or include will only return
the squad ofthe current season of the domestic league
the team is playing in. You can use this endpoint to load squads for a
different season or even for cups.
Args:
season_id:
id of the season
team_id:
id of the team
includes:
player
Returns:
Parsed HTTP response from SportMonks API.
JSON format.
"""
squads = self.make_request(endpoint=["squad", "season", season_id, "team", team_id],
includes=includes, filters=filters)
if df:
try:
df_squads = self._to_df(squads, cols=df_cols)
return df_squads
except NotJSONNormalizable:
log.info("Not JSON-normalizable, returning JSON.")
return squads
else:
return squads
def head2head(self, team1_id: int, team2_id: int,
includes: Optional[Union[str, List[str]]] = None,
filters: Optional[dict] = None,
df: bool = False, df_cols: Optional[Union[str, List[str]]] = None):
"""
The Head 2 Head endpoint provides you all previous Games between 2 Teams
Args:
team1_id:
id of team 1.
team2_id:
id of team 2.
includes: optional
Possible includes: localTeam, visitorTeam, substitutions, goals, cards,
other, events, corners,lineup, bench, sidelined, comments, tvstations,
highlights, round, stage, referee, venue, odds,
inplayOdds, flatOdds, localCoach, visitorCoach, group, trends.
***See Sportmonks.com for information regarding includes.
Returns:
Parsed HTTP response from SportMonks API.
JSON format.
"""
h2h = self.make_request(endpoint=["head2head", team1_id, team2_id],
includes=includes, filters=filters)
if df:
try:
df_h2h = self._to_df(h2h, cols=df_cols)
return df_h2h
except NotJSONNormalizable:
log.info("Not JSON-normalizable, returning JSON.")
return h2h
else:
return h2h
def head2head_results(self, team1_id: int, team2_id: int,
filters: Optional[dict] = None):
"""
Historic results between two teams.
Filter by season/league to return results from a season or league.
"""
response = self.head2head(team1_id=team1_id, team2_id=team2_id,
filters=filters, includes=["localTeam, visitorTeam"],
df=True, df_cols=["id", "league_id", "season_id",
"localteam_id", "localTeam.name",
"visitorteam_id", "visitorTeam.name",
"time.starting_at.date_time",
"scores.ft_score"])
response["time.starting_at.date_time"] = \
pd.to_datetime(response["time.starting_at.date_time"])
response.sort_values(by="time.starting_at.date_time", ascending=False)
return response
class Commentaries(BaseAPI):
"""Commentaries Class"""
def __init__(self, api_key: Optional[str] = None, timeout: Optional[int] = None):
super().__init__(api_key, timeout)
def commentaries(self, fixture_id: int, filters: Optional[dict] = None,
df: bool = False, df_cols: Optional[Union[str, List[str]]] = None):
"""
The Commentary endpoint can be used to request the Textual representation of
actions taken place in the Game.
Commentaries are marked as Important or Goal when they meet that criteria.
***NO INCLUDES AVAILABLE FOR THIS ENDPOINT
Args:
fixture_id:
id of the fixture
Returns:
Parsed HTTP response from SportMonks API.
JSON format.
"""
commentaries = self.make_request(endpoint=["commentaries", "fixture", fixture_id],
filters=filters)[::-1]
if df:
try:
df_commentaries = self._to_df(commentaries, cols=df_cols)
return df_commentaries
except NotJSONNormalizable:
log.info("Not JSON-normalizable, returning JSON.")
return commentaries
else:
return commentaries
class Venues(BaseAPI):
"""Venues class"""
def __init__(self, api_key: Optional[str] = None, timeout: Optional[int] = None):
super().__init__(api_key, timeout)
def by_id(self, venue_id: int, filters: Optional[dict] = None,
df: bool = False, df_cols: Optional[Union[str, List[str]]] = None):
"""
The Venue endpoint provides Venue information like Name, City,
Capacity, Address and even a Venue image.
If venue_id supplied, then info will be returned for that venue.
***NO INCLUDES AVAILABLE FOR THIS ENDPOINT
Args:
venue_id:
id of the venue you want to return.
Returns:
Parsed HTTP response from SportMonks API.
JSON format.
"""
venue = self.make_request(endpoint=["venues", venue_id], filters=filters)
if df:
try:
df_venue = self._to_df(venue, cols=df_cols)
return df_venue
except NotJSONNormalizable:
log.info("Not JSON-normalizable, returning JSON.")
return venue
else:
return venue
def by_season(self, season_id: int, filters: Optional[dict] = None,
df: bool = False, df_cols: Optional[Union[str, List[str]]] = None):
"""
The Venue endpoint provides Venue information like Name, City,
Capacity, Address and even a Venue image.
***NO INCLUDES AVAILABLE FOR THIS ENDPOINT
Args:
season_id:
id of the season you want to retrieve venues for.
Returns:
Parsed HTTP response from SportMonks API.
JSON format.
"""
venues = self.make_request(endpoint=["venues", "season", season_id], filters=filters)
if df:
try:
df_venues = self._to_df(venues, cols=df_cols)
return df_venues
except NotJSONNormalizable:
log.info("Not JSON-normalizable, returning JSON.")
return venues
else:
return venues
class Coaches(BaseAPI):
"""Coaches Class"""
def __init__(self, api_key: Optional[str] = None, timeout: Optional[int] = None):
super().__init__(api_key, timeout)
def coaches(self, coach_id: int, filters: Optional[dict] = None,
df: bool = False, df_cols: Optional[Union[str, List[str]]] = None):
"""
The Coaches endpoint provides you details about the Coach like its Name,
Nationality Birthdate etc. By default this endpoint returns Coach details that
have hosted at least 1 game under the Leagues covered by the
plan you are subscribed to.
***NO INCLUDES AVAILABLE FOR THIS ENDPOINT
Args:
coach_id:
id of the coach you want to return.
Returns:
Parsed HTTP response from SportMonks API.
JSON format.
"""
coach = self.make_request(endpoint=["coaches", coach_id], filters=filters)
if df:
try:
df_coach = self._to_df(coach, cols=df_cols)
return df_coach
except NotJSONNormalizable:
log.info("Not JSON-normalizable, returning JSON.")
return coach
else:
return coach
class Rounds(BaseAPI):
"""Rounds Class"""
def __init__(self, api_key: Optional[str] = None, timeout: Optional[int] = None):
super().__init__(api_key, timeout)
def by_round(self, round_id: int, filters: Optional[dict] = None,
includes: Optional[Union[str, List[str]]] = None,
df: bool = False, df_cols: Optional[Union[str, List[str]]] = None):
"""
Leagues can be split up in Rounds representing a week a game is played in.
With this endpoint we give you the ability to request data for a single
Round as well as all Rounds of a Season. The endpoint is often used in
combination with includes like Results or Fixtures to show them based on Rounds.
Args:
round_id:
id of the round you want returning.
includes:
Possible includes: fixtures, results, season, league.
Returns:
Parsed HTTP response from SportMonks API.
JSON format.
"""
rounds = self.make_request(endpoint=["rounds", round_id],
includes=includes, filters=filters)
if df:
try:
df_rounds = self._to_df(rounds, cols=df_cols)
return df_rounds
except NotJSONNormalizable:
log.info("Not JSON-normalizable, returning JSON.")
return rounds
else:
return rounds
def by_season(self, season_id: int, filters: Optional[dict] = None,
includes: Optional[Union[str, List[str]]] = None,
df: bool = False, df_cols: Optional[Union[str, List[str]]] = None):
"""
Leagues can be split up in Rounds representing a week a game is played in.
With this endpoint we give you the ability to request data for a single
Round as well as all Rounds of a Season. The endpoint is often used in
combination with includeslike Results or Fixtures to show them based on Rounds.
Returns ids of the gameweeks for the season.
Args:
season_id:
id of the season you want returning.
includes:
Possible includes: fixtures, results, season, league.
Returns:
Parsed HTTP response from SportMonks API.
JSON format.
"""
rounds = self.make_request(endpoint=["rounds", "season", season_id],
includes=includes, filters=filters)
if df:
try:
df_rounds = self._to_df(rounds, cols=df_cols)
return df_rounds
except NotJSONNormalizable:
log.info("Not JSON-normalizable, returning JSON.")
return rounds
else:
return rounds
class Stages(BaseAPI):
"""Stages Class"""
def __init__(self, api_key: Optional[str] = None, timeout: Optional[int] = None):
super().__init__(api_key, timeout)
def by_stage(self, stage_id: int, includes: Optional[Union[str, List[str]]] = None,
filters: Optional[dict] = None, df: bool = False,
df_cols: Optional[Union[str, List[str]]] = None):
"""
Leagues and Seasons all over the world can have a different set up.
The Stages endpoint can help you to define the current
Stage or set up of multiple Stages of a particular League/Season.
Stages names are for example: Regular Season, Play-offs, Semi-Finals, Final etc.
Args:
stage_id:
id of the stage you want to return info from.
includes:
Possible includes: fixtures, results, season, league
Returns:
Parsed HTTP response from SportMonks API.
JSON format.
"""
stages = self.make_request(endpoint=["stages", stage_id],
includes=includes, filters=filters)
if df:
try:
df_stages = self._to_df(stages, cols=df_cols)
return df_stages
except NotJSONNormalizable:
log.info("Not JSON-normalizable, returning JSON.")
return stages
else:
return stages
def by_season(self, season_id: int, includes: Optional[Union[str, List[str]]] = None,
filters: Optional[dict] = None, df: bool = False,
df_cols: Optional[Union[str, List[str]]] = None):
"""
Leagues and Seasons all over the world can have a different set up.
The Stages endpoint can help you to define the current
Stage or set up of multiple Stages of a particular League/Season.
Stages names are for example: Regular Season, Play-offs, Semi-Finals, Final etc.
Args:
season_id:
id of the season you want to return info from.
includes:
Possible includes: fixtures, results, season, league
Returns:
Parsed HTTP response from SportMonks API.
JSON format.
"""
seasons = self.make_request(endpoint=["stages", "season", season_id],
includes=includes, filters=filters)
if df:
try:
df_seasons = self._to_df(seasons, cols=df_cols)
return df_seasons
except NotJSONNormalizable:
log.info("Not JSON-normalizable, returning JSON.")
return seasons
else:
return seasons
class Players(BaseAPI):
"""Players Class"""
def __init__(self, api_key: Optional[str] = None, timeout: Optional[int] = None):
super().__init__(api_key, timeout)
def by_id(self, player_id: int, includes: Optional[Union[str, List[str]]] = None,
filters: Optional[dict] = None, df: bool = False,
df_cols: Optional[Union[str, List[str]]] = None):
"""
The Players endpoint provides you detailed Player information.
With this endpoint you will be able to build a complete Player Profile.
Args:
player_id:
id of the player.
includes: optional
Possible includes: position, team, stats, trophies,
sidelined, transfers, lineups, country.
***See Sportmonks.com for information regarding includes.
Returns:
Parsed HTTP response from SportMonks API.
JSON format.
"""
player = self.make_request(endpoint=["players", player_id],
includes=includes, filters=filters)
if df:
try:
df_player = self._to_df(player, cols=df_cols)
return df_player
except NotJSONNormalizable:
log.info("Not JSON-normalizable, returning JSON.")
return player
else:
return player
def by_name(self, search: str, includes: Optional[Union[str, List[str]]] = None,
filters: Optional[dict] = None, df: bool = False,
df_cols: Optional[Union[str, List[str]]] = None):
"""
The Players endpoint provides you detailed Player information.
With this endpoint you will be able to build a complete Player Profile.
Args:
search:
name of the player.
includes: optional
Possible includes: position, team, stats, trophies,
sidelined, transfers, lineups, country.
***See Sportmonks.com for information regarding includes.
Returns:
Parsed HTTP response from SportMonks API.
JSON format.
"""
players = self.make_request(endpoint=["players", "search", search],
includes=includes, filters=filters)
if df:
try:
df_players = self._to_df(players, cols=df_cols)
return df_players
except NotJSONNormalizable:
log.info("Not JSON-normalizable, returning JSON.")
return players
else:
return players
class Fixtures(BaseAPI):
"""Fixtures Class"""
def __init__(self, api_key: Optional[str] = None, timeout: Optional[int] = None):
super().__init__(api_key, timeout)
def by_id(self, fixture_ids: Union[int, List[int]],
markets: Optional[Union[int, List[int]]] = None,
bookmakers: Optional[Union[int, List[int]]] = None,
includes: Optional[Union[str, List[str]]] = None,
filters: Optional[dict] = None,
df: bool = False, df_cols: Optional[Union[str, List[str]]] = None):
"""
The Fixture endpoint provides information about Games in particular Leagues.
There are always 2 teams involved in a Fixture.
Args:
fixture_ids:
ids of the fixtures you want to return.
markets: optional
Filter odds based on the list of market ids.
If no markets specified, then all will be returned.
bookmakers: optional
Filter odds based on the list of bookmaker ids.
If no bookmakers are specified, then all will be returned.
includes: optional
Possible includes: localTeam, visitorTeam, substitutions, goals, cards,
other, events, corners,lineup, bench, sidelined, comments, tvstations,
highlights, round, stage, referee, venue, odds,
inplayOdds, flatOdds, localCoach, visitorCoach, group, trends, firstAssistant,
secondAssistant,fourthOfficial, stats, shootout,
league, stats, probability, valuebet.
***See Sportmonks.com for information regarding includes.