You are not logged in.

#1 2010-04-08 20:12:34

froli
Member
From: Germany
Registered: 2008-06-17
Posts: 455

[SOLVED][Request] Script that displays next NHL hockey games

Hi all! I am just wondering if someone would be able to write a script for me that displays the next game of the Montreal Canadiens (opponent, day date and time) and print the output in conky.

Example:

Away games--> Next game: @ CAR Thu. 08/04/2010 19h30
Home games --> Next game: VS TOR Sat. 10/04/2010 19h00

Thanks a lot! smile

Last edited by froli (2010-04-09 05:07:41)


archlinux on Macbook Pro 10,1

Offline

#2 2010-04-08 20:14:09

Daenyth
Forum Fellow
From: Boston, MA
Registered: 2008-02-24
Posts: 1,244

Re: [SOLVED][Request] Script that displays next NHL hockey games

And where is this information posted?

Offline

#3 2010-04-08 20:25:36

froli
Member
From: Germany
Registered: 2008-06-17
Posts: 455

Re: [SOLVED][Request] Script that displays next NHL hockey games


archlinux on Macbook Pro 10,1

Offline

#4 2010-04-08 20:34:40

bobdob
Member
Registered: 2008-06-13
Posts: 138

Re: [SOLVED][Request] Script that displays next NHL hockey games

After a quick look I found this which may be helpful:
http://www.nhl.com/ice/teamnext5games.htm?team=MTL

Offline

#5 2010-04-09 01:38:32

upsidaisium
Member
From: Vietnam
Registered: 2006-09-16
Posts: 263
Website

Re: [SOLVED][Request] Script that displays next NHL hockey games

bobdob wrote:

After a quick look I found this which may be helpful:
http://www.nhl.com/ice/teamnext5games.htm?team=MTL

but if he parses the output from that page, he won't know if a game is at home or away.


I've seen young people waste their time reading books about sensitive vampires. It's kinda sad. But you say it's not the end of the world... Well, maybe it is!

Offline

#6 2010-04-09 03:11:38

BetterLeftUnsaid
Member
From: My Happy Place
Registered: 2007-11-04
Posts: 78

Re: [SOLVED][Request] Script that displays next NHL hockey games

Just quickly threw this together using the link froli provided:

#!/usr/bin/env python
import urllib
import re

TEAM = "MTL"

def striphtml(data):
    # Strip comments or HTML tags or excess spaces
    data = re.sub(r"(?:<!--.*?-->)|(?:<[^>]*?>)|(?:[\t\r\f\v]*)", "", data)
    # Condence newlines
    return re.sub(r"\n{2,}", "\n", data)

def format(groups):
    # Prints the data with proper formatting
    for date, visiting, home, time in groups[-1::-1]:
        date = re.sub(r" ", " ", date)
        print "%s @ %s: %s %s" % (visiting, home, date, time)

if __name__ == "__main__":
    page = striphtml(urllib.urlopen("http://www.nhl.com/ice/schedulebyweek.htm?team=%s" % TEAM).read())
    format(re.findall(r"(\w{3} .*?)\n(.*?)\n(.*?)\n(.*?)\n", page))

Which will output the following:

MONTREAL @ CAROLINA: Thu Apr 8, 2010 7:30 PM ET
TORONTO @ MONTREAL: Sat Apr 10, 2010 7:00 PM ET

Let me know if there's something you want me to change (and go Sharks! =P).

Last edited by BetterLeftUnsaid (2010-04-09 03:16:58)

Offline

#7 2010-04-09 03:46:25

froli
Member
From: Germany
Registered: 2008-06-17
Posts: 455

Re: [SOLVED][Request] Script that displays next NHL hockey games

@BetterLeftUnsaid Excellent!! Is it possible to use shorten names? It's the only thing missing smile

Thanks a lot! (I like Sharks too! tongue)


archlinux on Macbook Pro 10,1

Offline

#8 2010-04-09 04:04:46

froli
Member
From: Germany
Registered: 2008-06-17
Posts: 455

Re: [SOLVED][Request] Script that displays next NHL hockey games

Also, Is it possible to display the next game only, instead of two?


archlinux on Macbook Pro 10,1

Offline

#9 2010-04-09 04:53:36

BetterLeftUnsaid
Member
From: My Happy Place
Registered: 2007-11-04
Posts: 78

Re: [SOLVED][Request] Script that displays next NHL hockey games

This should do it.  The line to shorten the team names requires Python 2.6, so if you're running 2.5 I'll change it around.

#!/usr/bin/env python
import urllib
import re

TEAM  = "mtl"
LIMIT = 1

# Teams whose abbriviated names
# are not the first 3 letters
teams = {
        "CALGARY" : "CGY",
        "COLUMBUS": "CBJ",
        "FLORIDA" : "FLA",
        "LOS ANGELES": "LAK",
        "MONTREAL": "MTL",
        "NASHVILLE": "NSH",
        "NEW JERSEY": "NJD",
        "NY ISLANDERS": "NYI",
        "NY RANGERS": "NYR",
        "PHOENIX": "PHX",
        "SAN JOSE": "SJS",
        "ST LOUIS": "STL",
        "TAMPA BAY": "TBL",
        "WASHINGTON": "WSH",
        }

def striphtml(data):
    # Strip comments or HTML tags or excess spaces
    data = re.sub(r"(?:<!--.*?-->)|(?:<[^>]*?>)|(?:[\t\r\f\v]*)", "", data)
    # Condence newlines
    return re.sub(r"\n{2,}", "\n", data)

def format(groups):
    # Prints the data with proper formatting
    for date, visiting, home, time in groups[-1::-1]:
        date = re.sub(r" ", " ", date)
        visiting, home = visiting.upper(), home.upper()
        visiting = visiting[:3] if not visiting in teams else teams[visiting]
        home = home[:3] if not home in teams else teams[home]
        print "%s @ %s: %s %s" % (visiting, home, date, time)

if __name__ == "__main__":
    page = striphtml(urllib.urlopen("http://www.nhl.com/ice/schedulebyweek.htm?team=%s" % TEAM).read())
    format(re.findall(r"(\w{3} .*?)\n(.*?)\n(.*?)\n(.*?)\n", page)[:LIMIT])

Offline

#10 2010-04-09 05:07:15

froli
Member
From: Germany
Registered: 2008-06-17
Posts: 455

Re: [SOLVED][Request] Script that displays next NHL hockey games

Perfect! Thank you so much! Good luck to Sharks! Hope they will stay on top of their game this year in the playoff this year tongue


archlinux on Macbook Pro 10,1

Offline

Board footer

Powered by FluxBB