Skip to content

lsissoko/python-ysports

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

YSports (v 0.1)

About

YSports is a python library for reading fantasy sports data from the Yahoo Sports API.

Version 0.1 allows the user to do three-legged authentication in order to query Yahoo Sports. Arbitrary queries can be made either via YQL or the REST API.

The YLeague class has been set up as the first instance of a class representing league data at a higher level of abstraction.

To Do

  • unit tests
  • better error handling
  • dynamically insert query parameters
  • secure token storage
  • flesh out YLeague
  • more classes for representing different data sets (e.g. Player, Roster, etc.)

Contributions

Bug fixes, features, patches, code improvements, etc. are always welcome.

Installation

Download from github.

Dependencies

  • httplib2
>>> pip install httplib2

Usage

Setup

Create an authorization csv file: ./ysports/cache/tokensecrets.csv

Enter your consumer key and consumer secret in the authorization csv file:

consumer_secret,consumer_key,token_key,token_secret,session_handle
<consumer_secret_here>,<consumer_key_here>,,,

Note: determine your own method for securely storing your authorization tokens. The method used in this library is not secure.

Sample Usage

The YLeague Object

Create an Auth object, then create a League object:

>>> import ysports
>>> Y = ysports.YAuth()
Enter Yahoo Authorization code: xxxxxx
>>> L = ysports.YLeague(Y, "<your_league_key>")
>>> L.name
# Your League Name

Arbitrary REST Query

>>> q1 = 'http://fantasysports.yahooapis.com/fantasy/v2/player/223.p.5479'
>>> response, content = Y.request(q1)
>>> print content
# [... fantasy info for Drew Brees, JSON format ...]

Arbitrary YQL Query

>>> q2 = 'select * from fantasysports.leagues.scoreboard where league_key="<your_league_key>"'
>>> response, content = Y.request_yql(q2)
>>> print content
# [... your league's info, JSON format ...]

About

Python YSports

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 100.0%