cdleong / pyfantasy

Not Playing Fantasy Sports
GNU General Public License v3.0
1 stars 0 forks source link

Read in Player Data #1

Closed cdleong closed 5 years ago

cdleong commented 5 years ago
cdleong commented 5 years ago

I'm thinking, let's connect to Yahoo and get live data?

https://developer.yahoo.com/fantasysports/guide/

cdleong commented 5 years ago

Actually, here's something: https://github.com/thorrr/YahooSports

cdleong commented 5 years ago

Sample Yahoo Sports data: https://developer.yahoo.com/fantasysports/guide/team-resource.html#team-resource-samples https://developer.yahoo.com/fantasysports/guide/player-resource.html#player-resource-desc

cdleong commented 5 years ago
<?xml version="1.0" ?><fantasy_content copyright="Data provided by Yahoo! and STATS, LLC" ns0:uri="http://fantasysports.yahooapis.com/fantasy/v2/game/nfl" refresh_rate="60" time="31.161069869995ms" xml:lang="en-US" xmlns:ns0="http://www.yahooapis.com/v1/base.rng">  
   <game>    
      <game_key>380</game_key>    
      <game_id>380</game_id>    
      <name>Football</name>    
      <code>nfl</code>    
      <type>full</type>    
      <url>https://football.fantasysports.yahoo.com/f1</url>    
      <season>2018</season>    
      <is_registration_over>0</is_registration_over>    
      <is_game_over>0</is_game_over>    
      <is_offseason>0</is_offseason>    
   </game>  
</fantasy_content>
cdleong commented 5 years ago

Managed to get data using https://github.com/thorrr/YahooSports

cdleong commented 5 years ago

Can I get league data if I have the league ID?

cdleong commented 5 years ago

Answer was yes.

Also, here's the main query for getting player data:

query = "game/nfl/players;out=draft_analysis,percent_owned" # get all the players, with percent_owned

But that only retrieves 25 results.

It essentially gives you the same things as going on https://football.fantasysports.yahoo.com/ and looking at the player list.

https://football.fantasysports.yahoo.com/f1/draftanalysis for example.

cdleong commented 5 years ago

You can modify it by filters like this:

query = "game/nfl/players;out=draft_analysis,percent_owned;position=" + position + ";count=" + str(count) + ";start=" + str(start)
cdleong commented 5 years ago

So I setup a loop to repeatedly query Yahoo until it starts giving me results

cdleong commented 5 years ago

Now to transform it into a form that I can work with programmatically.

cdleong commented 5 years ago

Two-part problem here:

Optional:

cdleong commented 5 years ago

My general go-to is to check https://github.com/vinta/awesome-python or https://docs.python-guide.org/

ooh, the "untangle" library looks good: https://github.com/stchris/untangle alternatively, xmltodict or xmldataset could be good.

The other part of the problem I haven't mentioned, is that I actually don't have one XML string, I have maybe a dozen.

cdleong commented 5 years ago

OK, decision to make. How do I want to handle the data? Make a Player object, or leave it in, like, a big table?

As a first initial goal, I think having one big dictionary or JSON with all 2789 entries would be a good place to start.

cdleong commented 5 years ago

So today we've got it into a big list at least. Next step, sorting based on fields like ADP or whatever