Skip to content

Instantly share code, notes, and snippets.

@jakebathman
Last active September 30, 2015 12:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jakebathman/bd6658331f6cb4b5a6de to your computer and use it in GitHub Desktop.
Save jakebathman/bd6658331f6cb4b5a6de to your computer and use it in GitHub Desktop.
NFL Game Picker (random)
<?php
$arrMap = array(
"gameId" => "eid",
"gsis" => "gsis",
"day" => "d",
"time" => "t",
"status" => "q",
"homeAbb" => "h",
"homeName" => "hnn",
"homeScore" => "hs",
"visAbb" => "v",
"visName" => "vnn",
"visScore" => "vs",
"rz" => "rz",
"ga" => "ga",
"gameType" => "gt"
);
$footballScores = [0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 3, 3, 3, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7];
$json = json_encode(simplexml_load_string(file_get_contents("http://www.nfl.com/liveupdate/scorestrip/ss.xml")));
$array = json_decode($json, TRUE);
foreach ($array['gms']['g'] as $k => $v)
{
foreach ($arrMap as $k2 => $v2)
{
$arrGames[$v['@attributes'][$arrMap['gameId']]][$k2] = $v['@attributes'][$v2];
}
}
$table = "<style>h3{margin:0px;}td{padding-left:4px;padding-right:4px;}h2{margin:0px;}</style><table style='text-align:center;'><thead><td><h2>AWAY</h2></td><td></td><td><h2>HOME</h2></td></thead>";
$lastDay = "Thu8:25";
foreach ($arrGames as $k => $v)
{
$arrG = array(
$v['homeName'],
$v['visName']
);
if ($lastDay !== $v['day'] . $v['time'])
{
$table.= "<tr style='background-color:red;'><td colspan=3 style='padding:2px;'></td></tr>";
}
mt_srand();
$pick = mt_rand(0, count($arrG) - 1);
$table.= "<tr>";
if ($v['status'] == "F")
{
$table.= "<td style='" . ($v['visScore'] > $v['homeScore'] ? "background:#7FFF69;" : "") . "'><h3>" . ucwords($arrG[1]) . "<br />" . $v['visScore'] . "</h3></td>";
$table.= "<td>@</td>";
$table.= "<td style='" . ($v['homeScore'] > $v['visScore'] ? "background:#7FFF69;" : "") . "'><h3>" . ucwords($arrG[0]) . "<br />" . $v['homeScore'] . "</h3></td>";
}
else
{
$table.= "<td style='" . ($pick === 1 ? "background:yellow;" : "") . "'><h3>" . ucwords($arrG[1]) . "</h3></td>";
$table.= "<td>@</td>";
$table.= "<td style='" . ($pick === 0 ? "background:yellow;" : "") . "'><h3>" . ucwords($arrG[0]) . "</h3></td>";
}
$table.= "</tr>";
$lastDay = $v['day'] . $v['time'];
}
$table.= "</table>";
echo $table;
echo "<br />";
echo "Optional tiebreaker scores";
echo "<br />";
$scoreTeam1 = 0;
$scoreTeam2 = 0;
while ($scoreTeam1 == $scoreTeam2)
{
$scoreTeam1 = 0;
$scoreTeam2 = 0;
for ($i = 0; $i < 7; $i++)
{
$scoreTeam1+= $footballScores[array_rand($footballScores) ];
$scoreTeam2+= $footballScores[array_rand($footballScores) ];
}
}
echo "Team 1: " . $scoreTeam1;
echo "<br />";
echo "Team 2: " . $scoreTeam2;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment