You are not logged in.
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!
Last edited by froli (2010-04-09 05:07:41)
archlinux on Macbook Pro 10,1
Offline
And where is this information posted?
[git] | [AURpkgs] | [arch-games]
Offline
archlinux on Macbook Pro 10,1
Offline
After a quick look I found this which may be helpful:
http://www.nhl.com/ice/teamnext5games.htm?team=MTL
Offline
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
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
@BetterLeftUnsaid Excellent!! Is it possible to use shorten names? It's the only thing missing
Thanks a lot! (I like Sharks too! )
archlinux on Macbook Pro 10,1
Offline
Also, Is it possible to display the next game only, instead of two?
archlinux on Macbook Pro 10,1
Offline
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
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
archlinux on Macbook Pro 10,1
Offline