Home

Awesome

script.module.thesportsdb

TheSportsDb Icon

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

teams = api.Search().Teams(team="Arsenal")
teams = api.Search().Teams(league="English Premier League")
teams = api.Search().Teams(sport="Soccer",country="England")
players = api.Search().Players(team="Arsenal")
players = api.Search().Players(player="Danny Welbeck")
players = api.Search().Players(team="Arsenal",player="Danny Welbeck")
events = api.Search().Events(event="Arsenal vs Chelsea")
events = api.Search().Events(filename="English_Premier_League_2015-04-26_Arsenal_vs_Chelsea")
events = api.Search().Events(event="Arsenal vs Chelsea",season=1415)
leagues = api.Search().Leagues(country="England")
leagues = api.Search().Leagues(sport="Soccer")
leagues = api.Search().Leagues(country="England",sport="Soccer")
seasons = api.Search().Seasons(leagueid=4328)
loves = api.Search().Loves(user="zag")
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

leagues = api.Lookups().League(leagueid=4346)
seasons = api.Lookups().Seasons(leagueid=4346)
teams = api.Lookups().Team(teamid=133604)
teams = api.Lookups().Team(leagueid=4346)
players = api.Lookups().Player(playerid=34145937)
players = api.Lookups().Player(teamid=133604)
events = api.Lookups().Event(eventid=441613)
table = api.Lookups().Table(leagueid=4346)
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

matches = api.Livescores().Soccer()
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

events = api.Schedules().Next().Team(teamid=133602)
events = api.Schedules().Next().League(leagueid=4328)
events = api.Schedules().Next().League(leagueid=4328,rnd=38)
events = api.Schedules().Last().Team(teamid=133602)
events = api.Schedules().Last().League(leagueid=4328)
events = api.Schedules().Lookup(datestring="2014-10-10")
import datetime
events = api.Schedules().Lookup(datetimedate=datetime.date(year=2014, month=10, day=10))
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 = 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 = api.Schedules().Lookup(leagueid=4328,rnd=38,season=1415)
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

Specific module Properties

####League Default Properties

Specific module Properties

####Player Default Properties

Specific module Properties

####Table entry

####Event Default Properties

Specific module Properties

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

Specific module Properties

####User