Code Monkey home page Code Monkey logo

nhl-api-py's Introduction

Hi there ๐Ÿ‘‹

I am Corey, a software engineer, AI explorer and game developer from Buffalo!

  • ๐Ÿ”ญ Iโ€™m currently working on Fear, a first person story driven game where you play as an amateur paranomal investigator (ghost hunter) in Unreal Engine 5.

  • ๐Ÿ“ซ How to reach me: coreyjs [at] hey.com, or on twitter @corey_s_ or Bluesky @coreyjs.dev

  • I write a weekly article called "The Bit Arcade" about life, my challenges, and my indie game dev journey. You can subscribe here, its free!

  • Go Sabres

nhl-api-py's People

Contributors

azaroth08 avatar coreyjs avatar dependabot[bot] avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

nhl-api-py's Issues

Helper integrations

Initial dev of the helper portion of the NHLClient(). This will include common functionality like consumes the other endpoints, such as returning an array of league standings that can be easily added to a DataFrame.

Lower Python version requirement

I got someone working on a fix for the nhl-led-scoreboard project and he's using your library to do so. The only issue I got is that some of my requirements breaks using Python 3.10 and up. would it be possible to make Python 3.9 the minimum requirement on your repo?

cheers

Passing optional date to schedule calls

I'm working on another project that is trying to pull the schedule for the future week as well as the current week. Would it be possible to slightly change functions calling the schedule api to optionally pass them a date? This would bring it in line with the pulling schedule by month.

Reduce payloads down to necessary info

Reduce payload down to specific information only. For example, c.teams.all() should return an array of teams, not an object with NHL meta data which also contains an array of teams.

New Endpoint - Clean Stats Season

Add new endpoints to map to available stats endpoints.

GET https://api-web.nhle.com/v1/club-stats-season/TEAM_ABBR

GET https://api-web.nhle.com/v1/player/PLAYER_ID/landing

GET https://api.nhle.com/stats/rest/en/{config/francise/country/season/draft}

Shift Charts

https://api.nhle.com/stats/rest/en/shiftcharts?cayenneExp=gameId%3D2023021148%20and%20((duration%20!%3D%20'00%3A00'%20and%20typeCode%20%3D%20517)%20or%20typeCode%20!%3D%20517%20)&exclude=eventDetails

Screenshot 2024-03-30 at 9 45 40โ€ฏAM

response:

"data": [
		{
			"id": 14117691,
			"detailCode": 0,
			"duration": "00:33",
			"endTime": "01:06",
			"eventDescription": null,
			"eventNumber": 105,
			"firstName": "Claude",
			"gameId": 2023021148,
			"hexValue": "#C8102E",
			"lastName": "Giroux",
			"period": 1,
			"playerId": 8473512,
			"shiftNumber": 1,
			"startTime": "00:33",
			"teamAbbrev": "OTT",
			"teamId": 9,
			"teamName": "Ottawa Senators",
			"typeCode": 517
		},
...

Increase timeout and allow for no SSL verification

The httpx library that you are using is showing a couple of issues when we are using it in our project for our next version(https://github.com/riffnshred/nhl-led-scoreboard)

We are seeing a timeout:

File "/usr/local/lib/python3.9/dist-packages/httpx/_transports/default.py", line 79, in map_httpcore_exceptions raise mapped_exc(message) from exc httpx.ReadTimeout: The read operation timed out

And an issue with SSL Verification (I believe this is likely because the Cloudflare Load Balancer that the NHL is using was returning a bad cert)
File "/usr/local/lib/python3.9/dist-packages/httpx/_transports/default.py", line 79, in map_httpcore_exceptions raise mapped_exc(message) from exc httpx.ConnectError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: Hostname mismatch, certificate is not valid for 'api-web.nhle.com'. (_ssl.c:1123)

With the httpx API you do have the ability to increase the time out and also disable SSL Verification. Would it be possible to add these as options to the NHLClient like you do with verbose logging?

https://www.python-httpx.org/advanced/#timeout-configuration

https://www.python-httpx.org/advanced/#ssl-certificates

I realize that turning off the SSL Verification is considered a bad idea but it is causing our scoreboard to crash. Having the option to allow a user to bypass the verification is a good option (as long as they understand the potential risk of doing this)

Async Stats Support

I am thinking about updating this to support async operations. If anyone has any feedback, for or against, I would love to hear it.

Add verbose flag to init for informative logging output

Is your feature request related to a problem? Please describe.
When instantiating a client, such as client = NHLClient() it would be nice to pass in an optional, defaulted to false, flag such as client = NHLClient(verbose=True). This can be used to display informative text such as the url that was generated, payload sizes, etc.

So the following in api/__init__.py:

    def _get(self, resource: str) -> httpx.request:
        """
        Private method to make a get request to the NHL API.  This wraps the lib httpx functionality.
        :param resource:
        :return:
        """
        print(f"{self.base_url}{self.api_ver}{resource}")
        r: httpx.request = httpx.get(url=f"{self.base_url}{self.api_ver}{resource}", follow_redirects=True)
        return r

would become

    def _get(self, resource: str) -> httpx.request:
        """
        Private method to make a get request to the NHL API.  This wraps the lib httpx functionality.
        :param resource:
        :return:
        """
        if self.verbose:
             print(f"{self.base_url}{self.api_ver}{resource}")
        r: httpx.request = httpx.get(url=f"{self.base_url}{self.api_ver}{resource}", follow_redirects=True)
        return r

And a simple test in tests/test_nhl_client.py

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.