derek-adair / nflgame

A working snapshot of nflgame (for historic purposes). This project is no longer active.
http://nflgame.derekadair.com
The Unlicense
331 stars 100 forks source link

Always return schedule data, even if gamecenter json is unavailable #68

Open derek-adair opened 5 years ago

derek-adair commented 5 years ago

I have strict requirements regarding the timing of games, namely, I want to execute code when a game is exactly 10 minutes out. Over the last two years this has been inconsistent; I suspect it is this line, and that the game-center json is unavailable.

As I do not want to re-impliment nflgame.live in my project that uses nflgame; My inclination is to have nflgame.game.Game return game meta data even when there is no game-center json. I am trying to implement this with as little side effects as I can, but this likely has a LOT of implications throughout the code.

derek-adair commented 5 years ago

Ok! took a crack at this. I think i did this in a way that will be unobtrusive. PLEASE take a look at my commit, and give me any feedback that you can provide.

Key points:

  1. Methods that return stats should return empty lists (e.g. max_player_stats)
  2. new game attribute: gcJsonAvailable for an easy flag (probably only useful for debugging)
    1. passing kwargs (games_gen, nflgame.one) into game instead of just eid or fpath
    2. if _get_json_data returns None; stub out an empty object
    3. limiting the attributes constructed if there is no game center data
derek-adair commented 5 years ago

This is made available under the 2.0.1a3 release in pypi.

OR you can check out dev and build locally

make dev-install

derek-adair commented 5 years ago

This... doesn't work. It breaks when you pass nflgame.game.Game() and the game is in the future. My thoughts were to always pass the entire schedule object for the game as kwargs.

Unsure the best way to do this anymore. Maybe if the extra schedule data isn't included, fetch it?

This would require modifying _search_schedule_by_eid, or something along those lines.

derek-adair commented 5 years ago
derek-adair commented 5 years ago

Fixed _search_schedule() by eid: It was failing b/c we are in pre-season and the default is REG.

I decided to just return a flat dict of the schedule data when an eid matches to simplify this.

derek-adair commented 5 years ago

Ruminating on if these changes are worth it.... I may just implement a live-esque script that just searches the schedule by week.

nczeak commented 4 years ago

I'm still having issues with this. It seems as though there are two try/except blocks to handle an HTTPError, and the nested block isn't allowing the outer block to properly handle the exception. Everything works perfectly for me when I delete the except urllib.error.HTTPError segment within _get_json_data(). Otherwise, instead of halting and returning None, __new__() will set rawData = None and cause an error when trying to decode.

derek-adair commented 4 years ago

@nczeak - Can you submit a PR or give some line numbers? I'd love to have more confidence in pushing this code beyond a "beta release"