Awesome
script.module.thesportsdb
A python module packaged as a Kodi script module to wrap all thesportsdb API methods and for you to use on your own addon. An API key is required, please visit thesportsdb for more information.
##Usage
###Addon.xml The module most be imported in the addon.xml of your addon and pointing to the correct version of the module
<import addon="script.module.thesportsdb" version="1.0.0"/>
###Pythonic usage
The module follows the API structure described Here. Every group method (Search,Lookups,Schedules,Livescores) is a Python class and all the endpoints (eg: lookupleague) is part of a class method. The module maps the json data to objects as much as possible, so each call returns one or more Team objects, League objects, Player objects, Livescores objects, Table objects, etc. Below all the classes and methods are explained with examples. Object properties are detailed later despite being exemplified some times.
###A really simple usage example...
import thesportsdb
api = thesportsdb.Api(key="1")
players = api.Search().Players(team="Arsenal")
for player in players:
print(player.strPlayer)
###Module methods
####Search
- Search for teams by name - (returns a list of team objects)
teams = api.Search().Teams(team="Arsenal")
- Search for all teams in a League - (returns a list of team objects)
teams = api.Search().Teams(league="English Premier League")
- Search for all Teams in a sport by country - (returns a list of team objects)
teams = api.Search().Teams(sport="Soccer",country="England")
- Search for all players from a team - (returns a list of player objects)
players = api.Search().Players(team="Arsenal")
- Search for players by name - (returns a list of player objects)
players = api.Search().Players(player="Danny Welbeck")
- Search for players by team and name - (returns a list of player objects)
players = api.Search().Players(team="Arsenal",player="Danny Welbeck")
- Search for events by event name - (returns a list of event objects)
events = api.Search().Events(event="Arsenal vs Chelsea")
- Search for events by filename - (returns a list of event objects)
events = api.Search().Events(filename="English_Premier_League_2015-04-26_Arsenal_vs_Chelsea")
- Search for event by event name and season - (returns a list of event objects)
events = api.Search().Events(event="Arsenal vs Chelsea",season=1415)
- Search for all Leagues in a country - (returns a list of league objects)
leagues = api.Search().Leagues(country="England")
- Search for all Leagues by sport - (returns a list of league objects)
leagues = api.Search().Leagues(sport="Soccer")
- Search for all Leagues in a country and by sport - (returns a list of league objects)
leagues = api.Search().Leagues(country="England",sport="Soccer")
- Search for all Seasons in a League provided the league id - (returns a list of strings each one identifying a season)
seasons = api.Search().Seasons(leagueid=4328)
- Search for all the user loved items - (returns single user object. Properties (Players,Events,Teams) are lists of id's - faster/need further lookup)
loves = api.Search().Loves(user="zag")
- Search for all the user loved items - (returns single user object. Properties (Players,Events,Teams) are lists of objects - slower/returns the object itself)
loves = api.Search().Loves(user="zag",objects=True)
A more detailed example using user loves:
import thesportsdb
api = thesportsdb.Api(key="1")
userloves = api.Search().Loves(user="zag")
print(userloves.Teams, userloves.Players, userloves.Events)
>> [u'133632', u'133597',....
userloves = api.Search().Loves(user="zag",objects=True)
print(userloves.Teams, userloves.Players, userloves.Events)
>> [<thesportsdb.team.Team instance at 0x129d4d200>, <thesportsdb.team.Team instance at 0x11e1ba5f0>,....
####Lookups
- Provides League Details given the leagueid (returns a list of league objects)
leagues = api.Lookups().League(leagueid=4346)
- League seasons by leagueid (returns a list of seasonid strings)
seasons = api.Lookups().Seasons(leagueid=4346)
- Provides Team Details given the teamid (returns a list of team objects)
teams = api.Lookups().Team(teamid=133604)
- All teams in a league provided the leagueid (returns a list of team objects)
teams = api.Lookups().Team(leagueid=4346)
- Provides Player Details given the playerid (returns a list of player objects)
players = api.Lookups().Player(playerid=34145937)
- All players in a team by teamid (returns a list of player objects)
players = api.Lookups().Player(teamid=133604)
- Provides Event Details given the eventid (returns a list of event objects)
events = api.Lookups().Event(eventid=441613)
- Lookup Table by League ID and Season (returns a list of tableentry objects without team objects)
table = api.Lookups().Table(leagueid=4346)
- Lookup Table by League ID and Season (returns a list of tableentry objects each one containing a team object as Team property)
table = api.Lookups().Table(leagueid=4346,objects=True)
A more detailed example using League Tables:
import thesportsdb
api = thesportsdb.Api(key="1")
table = api.Lookups().Table(leagueid=4346)
if table:
print(table[0].name,table[0].Team)
>> FC Dallas
>>
table = api.Lookups().Table(leagueid=4346,objects=True)
if table:
print(table[0].name,table[0].Team, table[0].Team.strTeamBadge)
>> FC Dallas
>> <thesportsdb.team.Team instance at 0x12768ab80>
>> http://www.thesportsdb.com/images/media/team/badge/xvrwus1420778297.png
####Livescores
- Soccer Livescores (returns a list of Livescores objects - no Team objects defined)
matches = api.Livescores().Soccer()
- Soccer Livescores (returns a list of Livescores objects - Team objects defined)
matches = api.Livescores().Soccer(objects=True)
A full example using Soccer livescores:
import thesportsdb
api = thesportsdb.Api(key="1")
matches = api.Livescores().Soccer(objects=True)
if matches:
for match in matches:
print("HomeTeam: %s HomeTeamLogo: %s %s:%s AwayTeam: %s AwayTeamLogo: %s" % (match.HomeTeam,match.HomeTeamObj.strTeamBadge,match.HomeGoals,match.AwayGoals,match.AwayTeam,match.AwayTeamObj.strTeamBadge))
####Schedules
- Next 5 Events by Team Id (returns a list of Event Objects)
events = api.Schedules().Next().Team(teamid=133602)
- Next 15 Events by League Id (returns a list of Event Objects)
events = api.Schedules().Next().League(leagueid=4328)
- Next 15 Events by League Id and Round (returns a list of Event Objects)
events = api.Schedules().Next().League(leagueid=4328,rnd=38)
- Last 5 Events by Team Id (returns a list of Event Objects)
events = api.Schedules().Last().Team(teamid=133602)
- Last 15 Events by League Id (returns a list of Event Objects)
events = api.Schedules().Last().League(leagueid=4328)
- Events on a specific day provided a date string (returns a list of Event Objects)
events = api.Schedules().Lookup(datestring="2014-10-10")
- Events on a specific day provided a datetime object (returns a list of Event Objects)
import datetime
events = api.Schedules().Lookup(datetimedate=datetime.date(year=2014, month=10, day=10))
- Events on a specific day by sport provided a date string or a datetime.date object (returns a list of Event Objects)
events = api.Schedules().Lookup(datestring="2014-10-10",sport="soccer")
events = api.Schedules().Lookup(datetimedate=datetime.date(year=2014, month=10, day=10),sport="soccer")
- Events on a specific day by league provided a date string or a datetime.date object (returns a list of Event Objects)
events = api.Schedules().Lookup(datestring="2014-10-10",league="Australian A-League")
events = api.Schedules().Lookup(datetimedate=datetime.date(year=2014, month=10, day=10),league="Australian A-League")
- Events in a specific round of a league by season (returns a list of Event Objects)
events = api.Schedules().Lookup(leagueid=4328,rnd=38,season=1415)
- All events in a specific league by season
events = api.Schedules().Lookup(leagueid=4328,season=1415)
####Images
TheSportsDB provides a way of getting a preview of the image. The same can be done in this module using api.Image().Preview(image)
. A full example is below:
import thesportsdb
api = thesportsdb.Api(key="1")
team = api.Lookups().Team(teamid=134108)[0]
print(team.strTeamFanart4)
print(api.Image().Preview(team.strTeamFanart4))
print(api.Image().Original(team.strTeamFanart4))
>>http://www.thesportsdb.com/images/media/team/fanart/wqywqq1421075962.jpg
>>http://www.thesportsdb.com/images/media/team/fanart/wqywqq1421075962.jpg/preview
>>http://www.thesportsdb.com/images/media/team/fanart/wqywqq1421075962.jpg
###Objects
####Team Default Properties
idTeam
- id of the team in thesportsdbidSoccerXML
- id of the team in soccerXMLintLoved
- number of thesportsdb users that love the teamstrTeam
- team namestrTeamShort
- short team namestrAlternate
- team alternative nameintFormedYear
- year of foundationstrSport
- sport the team is associated withstrLeague
- league in which the team is participatingidLeague
- the id of the league of the teamstrDivision
- division of the leaguestrManager
- team manager namestrStadium
- name of the team's stadiumstrKeywords
- keywords to help identifying the teamstrRSS
- RSS url for team newsstrStadiumThumb
- thumbnail of the stadiumstrStadiumDescription
- stadium descriptionstrStadiumLocation
- location of the stadiumstrWebsite
- official website of the teamstrFacebook
- official facebook page of the teamstrTwitter
- official team's twitter pagestrInstagram
- official team's instagram pagestrYoutube
- official team's youtube pagestrDescriptionEN
- team plot in English (might not be available)strDescriptionDE
- team plot in German (might not be available)strDescriptionFR
- team plot in French (might not be available)strDescriptionCN
- team plot in Chinese (might not be available)strDescriptionIT
- team plot in Italian (might not be available)strDescriptionJP
- team plot in Japanese (might not be available)strDescriptionRU
- team plot in Russian (might not be available)strDescriptionES
- team plot in Spanish (might not be available)strDescriptionPT
- team plot in Portuguese (might not be available)strDescriptionSE
- team plot in Swedish (might not be available)strDescriptionNL
- team plot in Dutch (might not be available)strDescriptionHU
- team plot in Hungarian (might not be available)strDescriptionNO
- team plot in Norwegian (might not be available)strDescriptionIL
- team plot in Hebrew (might not be available)strDescriptionPL
- team plot in Polish (might not be available)strGender
- team genderstrCountry
- country of the teamstrTeamBadge
- team badge (logo)strTeamJersey
- team jersey clearartstrTeamLogo
- team logo clearartstrTeamFanart1
- team fanart 1 (general)strTeamFanart2
- team fanart 2 (general)strTeamFanart3
- team fanart 3 (team)strTeamFanart4
- team fanart 4 (players)strTeamBanner
- team banner
Specific module Properties
AlternativeNameFirst
- Returns the alternative name of the team first and the default team name as fallbackFanartList
- Returns a python list containing all fanartsFanFanart
- Returns the fans fanart(3) or a random fanart as fallbackPlayerFanart
- Returns the player fanart or a random fanart as fallbackRandomFanart
- Returns a random fanart or None as fallbackstrDescription
- Returns the description of the team in the language your Kodi instalation is using. Fallback is done to English
####League Default Properties
idSoccerXML
- id of the league on soccerXMLstrSport
- sport of the leaguestrLeague
- league nameidLeague
- id of the league on the databasestrLeagueAlternate
- alternative league nameintFormedYear
- league formation yeardateFirstEvent
- date of the first eventstrGender
- gender of the leaguestrCountry
- country of the leaguestrWebsite
- league official websitestrFacebook
- league facebook pagestrTwitter
- league twitterstrYoutube
- league youtube channelstrRSS
- RSS feed with league newsstrDescriptionEN
- league plot in English (might not be available)strDescriptionDE
- league plot in German (might not be available)strDescriptionFR
- league plot in French (might not be available)strDescriptionCN
- league plot in Chinese (might not be available)strDescriptionIT
- league plot in Italian (might not be available)strDescriptionJP
- league plot in Japanese (might not be available)strDescriptionRU
- league plot in Russian (might not be available)strDescriptionES
- league plot in Spanish (might not be available)strDescriptionPT
- league plot in Portuguese (might not be available)strDescriptionSE
- league plot in Swedish (might not be available)strDescriptionNL
- league plot in Dutch (might not be available)strDescriptionHU
- league plot in Hungarian (might not be available)strDescriptionNO
- league plot in Norwegian (might not be available)strDescriptionIL
- league plot in Hebrew (might not be available)strDescriptionPL
- league plot in Polish (might not be available)strFanart1
- fanart 1 of the leaguestrFanart2
- fanart 2 of the leaguestrFanart3
- fanart 3 of the leaguestrFanart4
- fanart 4 of the leaguestrBanner
- league bannerstrBadge
- league badge (logo)strLogo
- league logo clearartstrPoster
- league posterstrTrophy
- league trophy clearartstrNaming
- league naming
Specific module Properties
AlternativeNameFirst
- Returns the alternative name of the team first and the default team name as fallbackFanartList
- Returns a python list containing all fanartsRandomFanart
- Returns a random fanart or None as fallbackstrDescription
- Returns the description of the team in the language your Kodi instalation is using. Fallback is done to English
####Player Default Properties
idPlayer
- player id on thesportsdbidTeam
- team id on thesportsdbidSoccerXML
- player id on soccerXMLidPlayerManager
- manager idstrNationality
- player nationalitystrPlayer
- player's namestrTeam
- player's team namestrSport
- player's sportintSoccerXMLTeamID
- team id on soccerXMLdateBorn
- birth date of the playerdateSigned
- sign date of the playerstrSigning
- signing value for the playerstrWage
- wage of the player (month)strDescriptionEN
- player plot in English (might not be available)strDescriptionDE
- player plot in German (might not be available)strDescriptionFR
- player plot in French (might not be available)strDescriptionCN
- player plot in Chinese (might not be available)strDescriptionIT
- player plot in Italian (might not be available)strDescriptionJP
- player plot in Japanese (might not be available)strDescriptionRU
- player plot in Russian (might not be available)strDescriptionES
- player plot in Spanish (might not be available)strDescriptionPT
- player plot in Portuguese (might not be available)strDescriptionSE
- player plot in Swedish (might not be available)strDescriptionNL
- player plot in Dutch (might not be available)strDescriptionHU
- player plot in Hungarian (might not be available)strDescriptionNO
- player plot in Norwegian (might not be available)strDescriptionIL
- player plot in Hebrew (might not be available)strDescriptionPL
- player plot in Polish (might not be available)strGender
- gender of the playerstrPosition
- position of the playerstrCollege
- college of the playerstrFacebook
- player's official facebook pagestrWebsite
- player's official websitestrTwitter
- player's official twitter pagestrInstagram
- player's official instagram pagestrYoutube
- player's official youtube pagestrHeight
- player's heightstrWeight
- player's weightintLoved
- number of users which love the player on thesportsdbstrThumb
- player's thumbstrCutout
- player's cutout (clearart)strFanart1
- player fanart 1strFanart2
- player fanart 2strFanart3
- player fanart 3strFanart4
- player fanart 4
Specific module Properties
strDescription
- Returns the description of the team in the language your Kodi instalation is using. Fallback is done to EnglishFanartList
- Returns a python list containing all fanartsRandomFanart
- Returns a random fanart or None as fallbackdateBornAsDatetime
- Returns the birth date of the player as a datetime.date objectdateSignedAsDatetime
- Returns the signing date of the player as a python datetime.date object
####Table entry
name
- name of the teamteamid
- id of the team on thesportsdbplayed
- number of played matchesgoalsfor
- number of goals scoredgoalsagainst
- number of goals sufferedgoalsdifference
- goal differencewin
- number of winsdraw
- number of drawsloss
- number of lossestotal
- number of pointsTeam
- a team object (defined if objects=True). All the other team properties are available
####Event Default Properties
idEvent
- id of the event on thesportsdbidSoccerXML
- id of the event on soccerXMLstrEvent
- event namestrFilename
- filename name that matches easily the eventstrSport
- sport of the eventidLeague
- id of the league on thesportsdb for the eventstrLeague
- name of the league on the thesportsdb for the eventstrSeason
- season identifier for the eventstrDescriptionEN
- description/plot of the event (english only)strHomeTeam
- name of the home teamstrAwayTeam
- name of the away teamintHomeScore
- score of the hometeamintRound
- round of the event on the league it refers tointAwayScore
- away scoreintSpectators
- number of spectatorsstrHomeGoalDetails
- details for the goals of the hometeamstrHomeRedCards
- details for the redcards of the hometeamstrHomeYellowCards
- details for the yellow cards of the hometeamstrHomeLineupGoalkeeper
- starter goalkeeper of the hometeamstrHomeLineupDefense
- starter defense of the hometeamstrHomeLineupMidfield
- starter midfielders of the hometeamstrHomeLineupForward
- starter forwarders of the hometeamstrHomeLineupSubstitutes
- substitutes/bench for the hometeamstrHomeFormation
- formation of the hometeam (eg 4-4-2)strAwayRedCards
- details for the redcards of the awayteamstrAwayYellowCards
- details for the yellow cards of the awayteamstrAwayGoalDetails
- away team goal detailsstrAwayLineupGoalkeeper
- starter goalkeeper of the awayteamstrAwayLineupDefense
- starter defense of the awayteamstrAwayLineupMidfield
- starter midfielders of the awayteamstrAwayLineupForward
- starter forwarders of the awayteamstrAwayLineupSubstitutes
- substitutes of the awayteamstrAwayFormation
- formation of the away teamintHomeShots
- number of shots for the hometeamintAwayShots
- number of away shots for the awayteamdateEvent
- date of the event (eg 2015-10-10)strDate
- date of the event (2015/10/10)strTime
- time of the event (eg 16:00:00+00:00)strTVStation
- tvstations of the eventidHomeTeam
- id of the hometeamidAwayTeam
- id of the awayteamstrResult
- result of the eventstrCircuit
- name of the circuit (motorsports)strCountry
- country of the event (motorsports)strCity
- city of the event (motorsports)strPoster
- poster of the eventstrFanart
- fanart of the eventstrThumb
- thumbnail of the eventstrBanner
- banner of the eventstrMap
- image of the map of the event (motorsports)
Specific module Properties
strDescription
- returns the description of the event (english only)eventDateTime
- returns a datetime object with the datetime of the event (GMT timezone)
Note: event lookups do not return the team objects. You need a second lookup using the teamId's to grab the team objects
####Livescores Default Properties
Date
- datetime string for the event time (eg: "2016-01-28T17:30:00+00:00" - GMT timezone)League
- League string for the live eventRound
- Round for the league of the live eventSpectators
- Number of spectators for the live eventHomeTeam
- Name of the hometeam for the live eventHomeTeam_Id
- Id for the hometeam for the live event on thesportsdbAwayTeam
- Name for the awayteam for the live eventAwayTeam_Id
- Id for the awayteam for the live event on thesportsdbTime
- time string for the matchHomeGoals
- Number of goals for the hometeamAwayGoals
- Number of goals for the awayteamHomeGoalDetails
- Details of the goals for the hometeamAwayGoalDetails
- Details of the goals for the awayteamHomeLineupGoalkeeper
- Details for the hometeam goalkeeperAwayLineupGoalkeeper
- Details for the awayteam goalkeeperHomeLineupDefense
- Details for the hometeam defenseAwayLineupDefense
- Details for the awayteam defenseHomeLineupMidfield
- Details for the hometeam midfieldersAwayLineupMidfield
- Details for the awayteam midfieldersHomeLineupForward
- Details for the hometeam forwardersAwayLineupForward
- Details for the awayteam forwardersHomeLineupSubstitutes
- Details for the hometeam benchAwayLineupSubstitutes
- Details for the awayteam benchHomeLineupCoach
- Hometeam coachAwayLineupCoach
- Awayteam coachHomeSubDetails
- Substitutions details for the hometeamAwaySubDetails
- Substitutions details for the awayteamHomeTeamFormation
- Formation of the hometeamAwayTeamFormation
- Formation of the awayteamLocation
- Location of the eventStadium
- Name of the stadium of the eventHomeTeamYellowCardDetails
- Details for the yellow cards of the hometeamAwayTeamYellowCardDetails
- Details for the yellow cards of the awayteamHomeTeamRedCardDetails
- Details for the redcards of the hometeamAwayTeamRedCardDetails
- Details for the redcards of the awayteamReferee
- Match referee nameHomeLineupCoach
- Home team coach nameAwayLineupCoach
- Away team coach name
Specific module Properties
DateTime
- Returns the date of the event as a python datetime object (GMT timezone)
####User
strUsername
- the user usernameTeams
- a list of teamids for the teams the user loves (or team objects if objects=True)Players
- a list of playerids for the players the user loves (or player objects if objects=True)Leagues
- a list of leagueids for the leagues the user loves (or league objects if objects=True)Events
- a list of eventids for the events the user loves (or event objects if objects=True)