Hockey-Info Release v1.0

https://gitlab.com/dword4/hockey-info

This is probably as “complete” as the Hockey-Info project may ever get so I figured its worth an actual blog post (and git tag at v1.0 too). A little over a year ago I was fed up with the NHL’s mobile website and decided I wanted to create something that gave me all the information without the associated fluff and annoyance. I had already spent time documenting the NHL API and using that knowledge to build smaller things like a sopel plugin for hockey stats. So I started throwing things together with Flask and suddenly hockey-info.online came to be!

Features

  • News Headlines
  • Scores view (only shows today’s games/scores)
  • Standings (grouped by Conference/Division and sometimes showing Wildcards)
  • Schedule (day, week and month views, team specific or league wide)
  • Team Views
    • Regular Season
    • Playoffs
    • Previous Games
  • Game details
    • Box Score information
    • Goals by period with details
    • Shots on goal by period
    • Penalties by period with details

Important Details

Built in Python 3 with Flask, Requests, and some various other bits and bobs. It runs either by itself with the usual process to launch a Flask application or if you are so inclined there is a Dockerfile that can be used to launch it with a little less pain.

There is some caching going on with requests_cache however this is by no means optimal, I would like to eventually do more work with a proper web cache but for now this works since the site is so light weight. I make use of CDNs for all the JavaScript so that also helps speed things up (and more importantly move the burden off of wherever you choose to run it in the first place).

Timezone awareness is non-existent, I basically converted everything from whatever the NHL stores (UTC time/date) to Eastern Time since that is where I live. I try to be very privacy conscious and I couldn’t justify the time expenditure in methods of determining user location for time conversion processes, if someone wants to suggest it or contribute it PRs are welcome.

Legal Considerations

I have zero affiliation with the NHL beyond sometimes buying their branded merchandise and viewing their games when I get the chance. There are no ads served by the application (or even any decent way to add them without altering all the templates) so I make no money from anything (not even the blog).

Quick Code: Repo List

So I ran into an interesting problem over the weekend, I forgot my 2FA token for Gitlab at home while I was away. My laptop’s SSH key was already loaded into Gitlab so I knew I could clone any of my repositories if only I could remember the exact name. That of course turned out to be the problem: I couldn’t remember the name of a specific repository that I wanted to work on. I even tried throwing a bunch of things at git clone to try to guess it and still had no luck. Enter the Gitlab API:

#!/usr/bin/env python3
                                                                                                                    import requests                                                                                                     from tabulate import tabulate
                                                                                                                    personal_token = 'asdfqwerzxcv1234'                                                                             user_id = 'dword4'                                                                                                                                                                                                                      base_url = 'https://gitlab.com/api/v4/'                                                                             repo_url = 'users/'+user_id+'/projects'                                                                                                                                                                                                 full_url = base_url + repo_url + '?private_token=' + personal_token                                                                                                                                                                     res = requests.get(full_url).json()
table = []
for project in res:                                                                                                     name = project['name']
    name_spaced = project['name_with_namespace']
    path = project['path']
    path_spaced = project['path_with_namespace']
    if project['description'] is None:                                                                                      description = ''                                                                                                else:                                                                                                                   description = project['description']                                                                            #print(name,'|', description)                                                                                       table.append([name, description])                                                                                                                                                                                                   print(tabulate(table, headers=["name","description"]))

This is of course super simplistic and does virtually no error checking, fancy formatting, etc. However now with a quick alias I can get a list of my repositories even when I do flake out and forget my token at home.

Youtube Essential Ripping Platform

So I have been a longtime user of youtube-dl for ages to archive some things (obscure music, recordings of tech talks) and figured it was worth taking some time to make a simple and easy to use way to achieve this that others could benefit from. More simply put I created a front-end with Python and Flask to sit on top of youtube-dl and make the process so easy non-technical people could use it. Thus YERP was born (https://gitlab.com/dword4/yerp) to fill that role. I know there are tons of other competiting ideas out there doing the exact same thing but I wanted to take a crack at it for my own home network and get it so simplified that all you had to do was run a Dockerfile and it would spring into existence without configuration.

The project is VERY green right now and things are moving around and changing alot (even in my head before code is committed to the repository) so don’t bank on things staying how they are. There are tons of little features I want to put in like folder organization, backups, flags for filetypes and the like which will take quite a while to figure out how I would like to implement them. So if you do run the program just beware and if you find something that can be done better feel free to submit a PR and I will gladly bring other code into the project since I am only one person and not exactly a professional at this to begin with.

Winter Improvements for Hockey-Info

Finally got around to a rather large update for this project, fixed some small bugs such as the L10 data being way wrong (was showing win-loss-ot for the entire seaseon) as well as added in missing stats for Goalies and made the display of previous game results more sensible. Also redid about 95% of the interface to use Bootstrap4 which has made the look more uniform throughout. If you are interested in seeing the code itself you can see that here, or if you just want to check out the live site which I host as well then you can head over to http://hockey-info.online.

Project: hockey-info

So I don’t always have great cell phone service, sometimes its weak 4G or even not 4G at all so modern designed apps suffer when bandwidth is a trickle at best. I would be away from home trying to find out whats going on with a Caps game and the NHL app would just be painfully slow or not work at all sometimes. Eventually I decided the only reasonable thing a hockey nerd such as myself could do was write something to fill this void, ideally something simple and effective to get me the information I wanted without a lot of overhead and frilly extra stuff I didn’t really care about.

The repos are still in high flux right now as I don’t even have a readme file yet for the main one, however this page can serve to sort of explain the bits and pieces.

nhlapi – This is what started it all for me really, I wanted more information about games (for an IRC bot) and threw myself into pulling various bits of information together about the NHL API in an easy to read and access way so others didn’t have to spend the hours I did looking for how to do things.

hockey-info – A super simple website written in Python utilizing the Flask framework. The focus is to be fast, simple and mobile friendly. It directly queries the NHL API for all its information and is formatted in a way that works well on mobile

hockey-info-docker – A bare bones Dockerfile to deploy the latest release of hockey-info. The container is based on Alpine and is as trimmed down as possible, makes deployment super simple and easy for anybody to run their own instance with only a few commands (provided you already have a Docker host to run it on).

Naturally I make no warranty about this app or any of the code I have written, its purely something neat I built in my spare time and am tossing out there for others to enjoy, modify and extend to their hearts content. If you do happen to have input, ideas, or feedback hit me up on twitter or just open an issue on Gitlab if its a purely technical issue to address with the code.

bhistory, a tool for nobody

Previously I enabled Timestamps in Bash to allow me to know when someone was doing stupid things, such as deleting vixie-cron or truncating databases at midnight, now I have system that backups all of the .bash_history files on my production system and stores them so I can look for stupid behavior, however the logfiles are a little unfriendly to the human eye

example of logfiles go here

This necessitated the creation of a script that would let me view the history file as it was originally viewable with the history command and the timestamps parsed, thus bhistory was created.

#!/usr/bin/python

import re
import time
import sys
import os.path

try: sys.argv[1]

except: sys.exit("nNo file specified!nUsage:nbhistory <filename>n")

if os.path.isfile(sys.argv[1]):
        # file exists!
        print ""
else:
        sys.exit("nfile doesn't exist, try againn")

with open(sys.argv[1]) as input_file:
        for i, line in enumerate(input_file):
                #print line,
                m_obj = re.search("^#",line)
                if m_obj:
                        new = line.strip('#')
                        print time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(int(new)))
                else :
                        print line
print "{0}line(s) printed".format(i+1)

Simple chmod the file, call it bhistory or whatever else you please and then drop it somewhere that your path statement covers and its time to view that logfile (and hopefully not find stupid things happening)

Usage: # bhistory /home/somebody/.bash_history

Naturally nobody should consider this a script that I support in any way, use this mess of code at your own discretion just make sure you have the timestamps enabled or not much is going to happen when you use it.

SSH Connection Script

Ever have a shitty environment where you have tons of devices that you need to connect to and don’t feel like typing out (and invariably mis-typing the hostname)?  Then this dirt simple script might be what you are looking for.

#!/usr/bin/env python
#
# requires file 'hosts' to exist in same directory as the script
# can accept either ip addresses or hostnames in this file

import os
import pwd

user = pwd.getpwuid( os.getuid() )[ 0 ]

f = open('hosts', 'r')

hosts = f.readlines()

id=0

print "=== SSH Console v1 ===nn"
for host in hosts:
        print str(id)+": "+host.rstrip("n")
        id += 1 

print "n"
choice = raw_input('Host >')
choice = int(choice)

os.system("ssh "+user+"@"+hosts[choice])

Just make sure the host file exists and has a hostname on each line rather than smashed together with some delimiter.  Its not elegant, has zero configuration but so far folks at work have found it somewhat handy to save some time, maybe you will too.

Powerball number picker

So I spent a little time the other day applying what little I know of Python to the concept of picking Powerball lottery numbers because I had nothing much else to do that the time.  In the interest of not only content put putting more of my terrible code out there for people to laugh at I present my simple powerball picker script.

#!/usr/bin/python
from array import *
from random import *
num = array('i')

def create_array():

        for i in range(0,59):
                ins = i + 1
                num.insert(i, ins)
        return num
def pick_a_number():
        your_number = ''
        for n in range(1,6):
                ca = create_array()
                pick = randrange(0,len(ca))
                your_number += str(ca[pick])
                your_number += '  '
                # now we exclude the number
                num.pop(pick)
        print "Your Picks >> "+your_number+" Powerball: "+str(randrange(1,36))

start = 1;
stop = int(raw_input("How many picks would you like to generate? "))

for p in range(start, stop+1):
        pick_a_number()

* note – if you win a huge jackpot with numbers from this send a few bills my way!

Close Bitnami banner
Bitnami