Thursday, December 18, 2008

 

test for scoring chance thing

Scoring Chances for NHL Game Number 20439

TeamPeriodTimeNoteOilersOpponent
EDM118:22
5121324358948213841425v5
EDM115:33
18263537517124223338415v5
EDM112:00
5121324358923213841425v5
EDM18:45
12133544718939233641
5v4
EDM16:02
10273537718338141821415v5
VAN12:03
512132435891417182341555v5
VAN219:44
1826354451771417182341555v5
VAN215:34
2735377178833892233415v5
VAN28:55
1213354477
23213841
4v4
EDM22:22
13273544778923182933415v5


#PlayerEVPPSH
5L. SMID210000
10S. HORCOFF100000
12R. NILSSON221000
13A. COGLIANO321000
18E. MOREAU110000
24S. STAIOS210000
26E. COLE110000
27D. PENNER210000
35D. ROLOSON541000
37D. GREBESHKOV210000
43J. STRUDWICK000000
44S. SOURAY121000
46Z. STORTINI000000
51K. BRODZIAK110000
71L. VISNOVSKY211000
77T. GILBERT120000
78M. POULIOT010000
83A. HEMSKY110000
89S. GAGNER311000

Saturday, December 09, 2006

 

Scouring the NHL.com game sheets with your browser

PHP is a scripting language for HTML. Embed it in any web page (assuming that your server supports PHP, and they almost all do besides blogger) and it does what it does.

There is tonnes of free web space available out there, usually with advertising on it. You could even open a free acount somewhere, save the red bit of text as "joanette.php" or whatever name,
on the server, and run it from any computer using your web browser.

Below, in dark red, is a little PHP script that prints off the header of the NHL.com gamesheet for every Oilers game that Joanette reffed in during the 20052006 season. It can be easily changed to search for anything else in any other year that the NHL has game sheets on it's server, which is back to the 2000-2001 season I think.



$searchtext = "Joannette";
$team = "EDMONTON OILERS";
$season = "20052006";

function url_exists($url)
{
$handle = @fopen($url, "r");
if ($handle === false)
return false;
fclose($handle);
return true;
}

function headerstr($str)
{
$str= strstr($str, "
$ender = strpos($str, "
");

$str = substr($str, 0, $ender);
return $str;
}

for ($m = 1; $m <= 1230; $m++){
$url = "http://www.nhl.com/scores/htmlreports/".$season."/GS0".($m + 20000).".HTM";
if (url_exists($url) == true ){
$str = file_get_contents($url);
if ( strpos( $str, $searchtext ) > 0){
if (strpos( $str, $team ) > 0) {
$tmp = headerstr($str);
echo $tmp."

";

}
}
}
}

?>

If you go to an NHL.com gamesheet such as this one, and go to view - page source (CTRL + U with firefox) using your browser, it should become readily apparent that you can search for almost anything using this simple script.

So for example, if you wanted to search for every game that Rod Brind'Amour elbowed in, you would cut and paste that bit from a gamesheet and enter it as the $searchtext term as such:

$searchtext = "17
R. BRIND'AMOUR
2:00
Elbowing";

Just remember to enclose it in brackets and put the semicolon at the end.

It's really straightforward once you have a go.

PS. Blogger won't let me paste the snippet from the nhl.com game sheets without automatically modifying the HTML, but a text editor will.

Let me know if you have a go.

Friday, July 21, 2006

 

A Bit About This Blog

A lot of terrific information is available from NHL.com. Most of it is pretty raw.

And a lot of people around internet land have scraped the info from there, dug through it to find what they were looking for, and crushed some hockey myths and made the rest of us a bit smarter about the NHL game along the way.

The idea here is that the process should be as painless as possible. It would take hours to sift through the information manually, and writing macro code in Excel can speed up that process a tonne. And hopefully a lot of the guys with ZERO programming skills, but good eyes, rational minds and a passion for the game ... hopefully some of those guys will see just how easy this is once you get past the first couple of hours on the learning curve. That's a big part of what I hope to accomplish with this specialized little blog. Folks like Lowetide, Dennis, Andy Grabia, and dozens others like them. Once they realize that it takes less time to prove (or disprove) their point in a compelling way ... less time than takes to actually argue about it ... then we're going to be moving forward with speed I think.

Personally I'm not a programmer, and have limited skills. Programmers are a strangely helpful bunch though, and in my experience they'll solve your problems for you if you just ask at an online forum.

Hopefully other people will want to contribute here, leaving bits of code to cut and paste to save everyone else from doing actual work :) . If you have something to post, please just send me an email or leave a note in the comments section and I'll send you the 'invite' link.

Let's keep it simple. And just Excel VBA code for here.

If I don't drag smart, non-computer types into the weird world of Roger Neilson ... then I've failed with this little venture.

 

Scraping data from NHL.com onto your hard drive

This macro strips the play-by-play sheets for the 0304 regular season off of the NHL.com database and into a directory called C:\NHL\PL0304. You will have to create the directory on your hard drive first, Or you can create a directory with a different name so long as you change the red bit of code below to match it.. By changing PL to GS in the code below you would be scraping the Game Sheets for thst season instead. By changing 20032004 to 20052006 you grab the sheets for theis past season. Simple enough, no?

BTW: I don't actually know how this code works, I just copied it from the net. But it does work for me.

Once you've created the directory on your hard drive, just open Excel, press Alt-F11, press Alt-I, press M, paste everything onto the sheet that shows up. Then press F5 and voila! You're scraping off data!

Little bits of code to come later will let you make use of this stuff you've scraped off in a simple and fast way.

Let me know if this works for anyone. Lowetide ... I'm looking at you. :-)

_____________________________________________________


Public Const INTERNET_OPEN_TYPE_PRECONFIG = 0
Public Const INTERNET_OPEN_TYPE_DIRECT = 1
Public Const INTERNET_OPEN_TYPE_PROXY = 3

Public Const scUserAgent = "VB OpenUrl"
Public Const INTERNET_FLAG_RELOAD = &H80000000

Public Declare Function InternetOpen Lib "wininet.dll" Alias _
"InternetOpenA" (ByVal sAgent As String, ByVal lAccessType _
As Long, ByVal sProxyName As String, ByVal sProxyBypass _
As String, ByVal lFlags As Long) As Long

Public Declare Function InternetOpenUrl Lib "wininet.dll" Alias _
"InternetOpenUrlA" (ByVal hOpen As Long, ByVal sUrl As String, _
ByVal sHeaders As String, ByVal lLength As Long, ByVal lFlags As _
Long, ByVal lContext As Long) As Long

Public Declare Function InternetReadFile Lib "wininet.dll" _
(ByVal hFile As Long, ByVal sBuffer As String, ByVal _
lNumBytesToRead As Long, lNumberOfBytesRead As Long) As Integer

Public Declare Function InternetCloseHandle Lib "wininet.dll" _
(ByVal hInet As Long) As Integer

Public Declare Function GIFToBMP Lib "gif2bmp.dll" _
(ByVal lpstrGIF As String, ByVal lpstrBMP As String) As Integer


Sub GetHTMLFromURL()

Dim sUrl As String
Dim s As String
Dim hOpen As Long
Dim hOpenUrl As Long
Dim bDoLoop As Boolean
Dim bRet As Boolean
Dim sReadBuffer As String * 2048
Dim lNumberOfBytesRead As Long
Dim j As Integer: Dim i As Integer: Dim m As Integer
Dim k As Long
Dim sG() As Byte


On Error GoTo NEXTj

For j = 1 To 1230

m = 20000 + j

s = Empty
sUrl = "http://www.nhl.com/scores/htmlreports/20032004/PL0" & m & ".HTM"

hOpen = InternetOpen(scUserAgent, INTERNET_OPEN_TYPE_PRECONFIG, vbNullString, vbNullString, 0)
hOpenUrl = InternetOpenUrl(hOpen, sUrl, vbNullString, 0, INTERNET_FLAG_RELOAD, 0)

bDoLoop = True
While bDoLoop
sReadBuffer = vbNullString
bRet = InternetReadFile(hOpenUrl, sReadBuffer, Len(sReadBuffer), lNumberOfBytesRead)
s = s & Left$(sReadBuffer, lNumberOfBytesRead)
If Not CBool(lNumberOfBytesRead) Then bDoLoop = False
Wend

If hOpenUrl <> 0 Then InternetCloseHandle (hOpenUrl)
If hOpen <> 0 Then InternetCloseHandle (hOpen)
k = Len(s)

ReDim sG(k) As Byte

For i = 1 To k: sG(i) = Asc(Mid(s, i, 1)): Next i

Open "C:\NHL\PL0304\PL0" & m & ".HTM" For Binary As #44 Len = 1
For i = 1 To k: Put #44, i, sG(i): Next i
Close #44

NEXTj:
Next j

End Sub

This page is powered by Blogger. Isn't yours?