-
Notifications
You must be signed in to change notification settings - Fork 57
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Bug Fix] Load Scores no longer working (fix inside) #45
Comments
I tried this out but didn't work for all the games. Week 1 - just the CLE v BAL game worked. Week 2 - CIN v CLE game only. |
Yeah, it didn't work for past weeks, only the current one. There was also a problem with the Washington abbreviation. These have both been fixed in this version:
|
This last version worked perfectly.
Thanks!
… On Sep 18, 2020, at 12:14 AM, jstackman ***@***.***> wrote:
Yeah, it didn't work for past weeks, only the current one. There was also a problem with the Washington abbreviation. These have both been fixed in this version:
<?php
require('includes/application_top.php');
$week = (int)$_GET['week'];
//load source code, depending on the current week, of the website into a variable as a string
//$url = "http://www.nfl.com/ajax/scorestrip?season=".SEASON_YEAR."&seasonType=REG&week=".$week;
$url = "https://site.api.espn.com/apis/site/v2/sports/football/nfl/scoreboard?week=".$week;
if ($xmlData = file_get_contents($url)) {
$games = json_decode($xmlData, true);
}
//build scores array, to group teams and scores together in games
$scores = array();
foreach ($games['events'] as $gameArray) {
$game = $gameArray['competitions'][0];
if ($game['status']['type']['completed'] == true) {
$overtime = (($game['status']['period'] == '5') ? 1 : 0);
foreach ($game['competitors'] as $gameTeams) {
if ($gameTeams['homeAway'] == "home") {
$home_team = $gameTeams['team']['abbreviation'];
$home_score = (int)$gameTeams['score'];
if ($home_team == "WSH")
$home_team = "WAS";
}
if ($gameTeams['homeAway'] == "away") {
$away_team = $gameTeams['team']['abbreviation'];
$away_score = (int)$gameTeams['score'];
if ($away_team == "WSH")
$away_team = "WAS";
}
}
$winner = ($away_score > $home_score) ? $away_team : $home_team;
$gameID = getGameIDByTeamID($week, $home_team);
if (is_numeric(strip_tags($home_score)) && is_numeric(strip_tags($away_score))) {
if ($away_score > 0 || $home_score > 0) {
$scores[] = array(
'gameID' => $gameID,
'awayteam' => $away_team,
'visitorScore' => $away_score,
'hometeam' => $home_team,
'homeScore' => $home_score,
'overtime' => $overtime,
'winner' => $winner
);
}
}
}
}
//see how the scores array looks
//echo '<pre>' . print_r($scores, true) . '</pre>';
echo json_encode($scores);
//game results and winning teams can now be accessed from the scores array
//e.g. $scores[0]['awayteam'] contains the name of the away team (['awayteam'] part) from the first game on the page ([0] part)
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub <#45 (comment)>, or unsubscribe <https://github.com/notifications/unsubscribe-auth/ARBLOZB5KB5FUGBI6XHJQE3SGLUEVANCNFSM4RITFYPQ>.
|
Last version seemed to work great for week 2! Thanks so much! |
Thanks again for getting this working from last year. Works great this year as well. You are life saver! :-) jstackman |
Question for @jstackman if you may be able to help here... So there was code that was able to get scores auto from nfl, but since that's not available, is the fix somehow able to use in a cron job like this to pull in automatically? |
The NFL now requires an API key to access their data so the "Load Scores" button no longer works in the admin panel. I found a free feed from ESPN that I am using now. I have only tested this on the Chiefs and Texans game so far, so there could be some issues with it still. Specifically, I am not sure how the feed shows overtime, so I made a guess. I also don't know if all the team abbreviations will match up.
All you need to do is update the getHtmlScores.php file:
The text was updated successfully, but these errors were encountered: