Git Product home page Git Product logo

hockepy's Introduction

 ____  ____    ____      ______  ___  ____   _________  ______    ____  ____
|_   ||   _| .'    `.  .' ___  ||_  ||_  _| |_   ___  ||_   __ \ |_  _||_  _|
  | |__| |  /  .--.  \/ .'   \_|  | |_/ /     | |_  \_|  | |__) |  \ \  / /
  |  __  |  | |    | || |         |  __'.     |  _|  _   |  ___/    \ \/ /
 _| |  | |_ \  `--'  /\ `.___.'\ _| |  \ \_  _| |___/ | _| |_       _|  |_
|____||____| `.____.'  `._____.'|____||____||_________||_____|     |______|

(pronounced like hockey-py so probably something like /ˈhɑː.kipaɪ/)

Build Status Codacy Badge Total alerts Language grade: Python Updates

Installation

pip install hockepy

CLI utility

The main purpose of hockepy is to provide a command line utility for geeky hockey fans. The easiest way to discover the features currently implemented is to display help:

  $ hockepy -h
usage: hocke.py [-h] [-D] [-v] {today,schedule} ...

positional arguments:
  {today,schedule}

optional arguments:
  -h, --help        show this help message and exit
  -D, --debug       turn debug output on
  -v, --verbose     turn verbose output on

Subcommands also support -h option:

$ hockepy schedule -h
usage: hocke.py schedule [-h] [--home-first] [--utc]
                           [first_date] [last_date]

positional arguments:
  first_date    first date to get schedule for
  last_date     last date to get schedule for

optional arguments:
  -h, --help    show this help message and exit
  --home-first  print the home team first
  --utc         print times in UTC instead of local time

Bear in mind that the actual help may differ as this listing won't necessarily be updated with any feature addition/change.

Configuration

You can highlight your favorite team using a configuration file called .hockepy.conf (an example is included in the repository):

highlight_teams = [
    "Boston Bruins",
    "Pittsburgh Penguins",
]

The file can be placed in the current working directory, your home directory or in a directory specified by HOCKEPY_CONF_DIR (hockepy checks in that order).

NHL API

Another goal is to offer a Python interface to a subset of NHL API. Other leagues may or may not be added as well but the main plan is to support NHL for now.

NHL API is available at https://statsapi.web.nhl.com/api/v1/. I am not aware of any available documentation so it's been discovering and trial-and-error for me so far. If you know about any documentation, let me know.

Please note that any usage of the API (and therefore usage of hockepy as well) is likely subject to NHL Terms of Service.

hockepy's People

Contributors

codacy-badger avatar dependabot-preview[bot] avatar dependabot[bot] avatar geckon avatar lgtm-migrator avatar pyup-bot avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Forkers

lgtm-migrator

hockepy's Issues

Make Game league agnostic

Game namedtuple (can be changed to "full" class too) should probably be league agnostic and not tailored for the NHL only.

Use currentPlay for last play

Current implementation reads allPlays in the feed and returns the last one. The feed provides also currentPlay which is probably more efficient to use.

hockepy 'crashes' when there is no subcommand in debug mode

$ ./hockepy.py
Command missing. Run `./hockepy.py -h' for help.

$ ./hockepy.py -D
DEBUG: hockepy: Discovered commands: dict_keys(['schedule', 'today'])
Traceback (most recent call last):
File "./hockepy.py", line 58, in
run_hockepy()
File "./hockepy.py", line 52, in run_hockepy
command = cmds[args.command_name]
KeyError: None

Make it exit more nicely.

schedule: alignment not correct for long team names

For certain combination of teams the alignment of schedule is not pretty.

Example:
$ ./hockepy.py schedule 2017-03-13 Schedule for 2017-03-13 Tampa Bay Lightning @ New York Rangers 23:00 UTC Columbus Blue Jackets @ Philadelphia Flyers 23:00 UTC Carolina Hurricanes @ New York Islanders 23:30 UTC Winnipeg Jets @ Nashville Predators 00:00 UTC Pittsburgh Penguins @ Calgary Flames 01:00 UTC Boston Bruins @ Vancouver Canucks 02:00 UTC Colorado Avalanche @ Arizona Coyotes 02:00 UTC St. Louis Blues @ Los Angeles Kings 02:00 UTC

DST seems to be always taken into account

E.g. the schedule times are displayed in CEST even though it's not DST anymore now in November.

$ ./hocke.py today
Schedule for 2019-11-13
R        Ottawa Senators @ New Jersey Devils     02:00 CEST        (scheduled) 
R    Toronto Maple Leafs @ New York Islanders    02:00 CEST        (scheduled) 
R    Washington Capitals @ Philadelphia Flyers   02:30 CEST        (scheduled) 
R           Dallas Stars @ Calgary Flames        04:30 CEST        (scheduled) 
R     Chicago Blackhawks @ Vegas Golden Knights  05:00 CEST        (scheduled)

The times are actually correct but displayed for a different timezone, e.g. the first game should be listed as starting at 1 am CET.

Highlighting teams breaks schedule visual structure

When teams are highlighted (see #39), the schedule "table" structure is a bit broken.

For example (without highlighting teams):

$ ./hocke.py schedule 2019-10-29
Schedule for 2019-10-29
R       San Jose Sharks @ Boston Bruins        01:00 CEST     (scheduled) 
R   Washington Capitals @ Toronto Maple Leafs  01:00 CEST     (scheduled) 
R   Philadelphia Flyers @ Pittsburgh Penguins  01:00 CEST     (scheduled) 
R        Calgary Flames @ Carolina Hurricanes  01:00 CEST     (scheduled) 
R   Tampa Bay Lightning @ New York Rangers     01:30 CEST     (scheduled) 
R       Edmonton Oilers @ Detroit Red Wings    01:30 CEST     (scheduled) 
R    Chicago Blackhawks @ Nashville Predators  02:00 CEST     (scheduled) 
R        Minnesota Wild @ Dallas Stars         02:30 CEST     (scheduled) 
R         Winnipeg Jets @ Anaheim Ducks        04:00 CEST     (scheduled) 

With Boston and Pittsburgh highlighted:

$ ./hocke.py schedule 2019-10-29
Schedule for 2019-10-29
R       San Jose Sharks @ Boston Bruins 01:00 CEST     (scheduled) 
R   Washington Capitals @ Toronto Maple Leafs  01:00 CEST     (scheduled) 
R   Philadelphia Flyers @ Pittsburgh Penguins 01:00 CEST     (scheduled) 
R        Calgary Flames @ Carolina Hurricanes  01:00 CEST     (scheduled) 
R   Tampa Bay Lightning @ New York Rangers     01:30 CEST     (scheduled) 
R       Edmonton Oilers @ Detroit Red Wings    01:30 CEST     (scheduled) 
R    Chicago Blackhawks @ Nashville Predators  02:00 CEST     (scheduled) 
R        Minnesota Wild @ Dallas Stars         02:30 CEST     (scheduled) 
R         Winnipeg Jets @ Anaheim Ducks        04:00 CEST     (scheduled) 

Add support for status "postponed"

E.g.

{
      "gamePk" : 2019021109,
      "link" : "/api/v1/game/2019021109/feed/live",
      "gameType" : "R",
      "season" : "20192020",
      "gameDate" : "2020-03-15T17:30:00Z",
      "status" : {
        "abstractGameState" : "Preview",
        "codedGameState" : "9",
        "detailedState" : "Postponed",
        "statusCode" : "9",
        "startTimeTBD" : false
      },
      "teams" : {
        "away" : {
          "leagueRecord" : {
            "wins" : 37,
            "losses" : 25,
            "ot" : 9,
            "type" : "league"
          },
          "score" : 0,
          "team" : {
            "id" : 22,
            "name" : "Edmonton Oilers",
            "link" : "/api/v1/teams/22"
          }
        },
        "home" : {
          "leagueRecord" : {
            "wins" : 41,
            "losses" : 21,
            "ot" : 7,
            "type" : "league"
          },
          "score" : 0,
          "team" : {
            "id" : 4,
            "name" : "Philadelphia Flyers",
            "link" : "/api/v1/teams/4"
          }
        }
      },
      "venue" : {
        "id" : 5096,
        "name" : "Wells Fargo Center",
        "link" : "/api/v1/venues/5096"
      },
      "content" : {
        "link" : "/api/v1/game/2019021109/content"
      }
    }

Find a way to share argparse options between schedule and today commands

pylint righteously complains about code duplication:

R:  1, 0: Similar lines in 2 files
==hockepy.commands.schedule:50
==hockepy.commands.today:40
        parser.add_argument('--home-first', dest='home_first',
                            action='store_true',
                            help='print the home team first')
        parser.add_argument('--utc', dest='utc', action='store_true',
                            help='print times in UTC instead of local time')
        return parser
 (duplicate-code)

There should be a way of sharing CLI options with a subclassed command

Make 'schedule' command more generic

As of now, it's only possible to print schedule for one day. It'd be nice to be able to print it for multiple days at once (providing a start and an end dates).

Add scores to schedule

When listing games (schedule/today commands), print also their score for finished games or ones in progress.

Allow printing game times in UTC.

Add an option to override printing the game times (for schedule/today commands) in local time zone (which should still be the default) and use UTC instead.

Deal with two pylint errors in hockepy.game caused by bugs in pylint

Disable (temporarily) the following two pylint errors:

************* Module hockepy.game
E: 64,15: Method 'name' has no 'lower' member (no-member)
E: 75,15: Value 'self.value' is unsubscriptable (unsubscriptable-object)

As mentioned in a relevant commit message (33d7849) those two are caused by (now confirmed) bugs in pylint:
pylint-dev/pylint#2062
pylint-dev/pylint#2063

Until those are fixed, it'll be better to ignore those two issues.

Add last play

Should it be a part of the schedule? Maybe with an option only? Or separate command?

Inconsistency between `hockepy.py -Dv' and `hockepy.py -vD'

Options help...

$ ./hockepy.py -h
usage: hockepy.py [-h] [-D] [-v] {schedule,today} ...

positional arguments:
  {schedule,today}

optional arguments:
  -h, --help        show this help message and exit
  -D, --debug       turn debug output on
  -v, --verbose     turn verbose output on

Different output depending on the options' order:

$ ./hockepy.py -Dv today
INFO: Retrieving NHL schedule for 2017-02-05.
Los Angeles Kings @ Washington Capitals
  Edmonton Oilers @ Montréal Canadiens
   Calgary Flames @ New York Rangers

$ ./hockepy.py -vD today
DEBUG  : hockepy       : Discovered commands: dict_keys(['schedule', 'today'])
DEBUG  : today         : Running the 'today' command.
DEBUG  : schedule      : Running the 'schedule' command.
DEBUG  : schedule      : Date empty -> using today (2017-02-05).
INFO: Retrieving NHL schedule for 2017-02-05.
DEBUG  : connectionpool: Starting new HTTPS connection (1): statsapi.web.nhl.com
DEBUG  : connectionpool: https://statsapi.web.nhl.com:443 "GET /api/v1/schedule?startDate=2017-02-05&endDate=2017-02-05 HTTP/1.1" 200 None
Los Angeles Kings @ Washington Capitals
  Edmonton Oilers @ Montréal Canadiens
   Calgary Flames @ New York Rangers

This shouldn't be different. It's desired to see debug output if -D is specified, no matter the -v presence.

Add support for game status

Add game status to the output.

Examples of status:

"status" : {
        "abstractGameState" : "Final",
        "codedGameState" : "7",
        "detailedState" : "Final",
        "statusCode" : "7",
        "startTimeTBD" : false
      },

"status" : {
        "abstractGameState" : "Preview",
        "codedGameState" : "1",
        "detailedState" : "Scheduled",
        "statusCode" : "1",
        "startTimeTBD" : false
      },

New NHL API

NHL changed their API, this needs some serious updates.

Date argument for schedule command not validated

$ ./hockepy.py schedule abc
Traceback (most recent call last):
  File "./hockepy.py", line 73, in <module>
    run_hockepy()
  File "./hockepy.py", line 68, in run_hockepy
    command.run()
  File "/home/theger/s/ws/hockepy/hockepy/commands/schedule.py", line 89, in run
    schedule = nhl.get_schedule(self.args.first_date, self.args.last_date)
  File "/home/theger/s/ws/hockepy/hockepy/nhl.py", line 53, in get_schedule
    if schedule['totalGames'] == 0:
KeyError: 'totalGames'

Initial Update

The bot created this issue to inform you that pyup.io has been set up on this repo.
Once you have closed it, the bot will open pull requests for updates as soon as they are available.

Update README

README contains old examples (e.g. '--home-first' argument is not mentioned there).

Wrongly interpreted status for future games with time TBD

$ hocke.py schedule 2018-05-08
Schedule for 2018-05-08
PO   Tampa Bay Lightning @ Boston Bruins         09:00 CEST 0:0 (final) 
PO       San Jose Sharks @ Vegas Golden Knights  09:00 CEST 0:0 (final) 

$ date
Sun May  6 01:18:49 CEST 2018

That displayed status should not be "final" as it's obviously in the future. Also the time is fishy.

Allow highlighting certain teams

For today/schedule commands allow highlighting (e.g. bold) certain (configurable) teams. This can be done based on an option or conf file.

Fix schedule output after adding enums

After implementing #25 the schedule command's output doesn't look very pretty. The way of displaying
game type and game status needs to be improved.

$ ./hocke.py schedule
Schedule for 2018-05-04
GameType.PLAYOFFS   Tampa Bay Lightning @ Boston Bruins         01:00 CEST     (GameStatus.SCHEDULED)
GameType.PLAYOFFS       San Jose Sharks @ Vegas Golden Knights  04:00 CEST     (GameStatus.SCHEDULED)

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.