Skip to content
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

Add ability to auto-update scores via cron job #19

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions getHtmlScores.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
require('includes/application_top.php');

$week = (int)$_GET['week'];
if (empty($week)) {
//get current week
$week = (int)getCurrentWeek();
}

//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;
Expand Down Expand Up @@ -61,3 +65,18 @@

//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)


//automatically update DB with scores if page is called by cronjob,etc
if(BATCH_SCORE_UPDATE_ENABLED && !empty($_GET['BATCH_SCORE_UPDATE_KEY']) && $_GET['BATCH_SCORE_UPDATE_KEY'] == BATCH_SCORE_UPDATE_KEY ){
foreach($scores as $game) {
$homeScore = ((strlen($game['homeScore']) > 0) ? $game['homeScore'] : 'NULL');
$visitorScore = ((strlen($game['visitorScore']) > 0) ? $game['visitorScore'] : 'NULL');
$overtime = ((!empty($game['OT'])) ? '1' : '0');
$sql = "update " . DB_PREFIX . "schedule ";
$sql .= "set homeScore = " . $homeScore . ", visitorScore = " . $visitorScore . ", overtime = " . $overtime . " ";
$sql .= "where gameID = " . $game['gameID'];
$mysqli->query($sql) or die('Error updating score: ' . $mysqli->error);
//echo $sql . '<BR>';
}
}
2 changes: 1 addition & 1 deletion includes/application_top.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
$adminUser = $login->get_user('admin');
//print_r($adminUser);

$okFiles = array('login.php', 'signup.php', 'password_reset.php');
$okFiles = array('login.php', 'signup.php', 'password_reset.php', 'getHtmlScores.php');
if (!in_array(basename($_SERVER['PHP_SELF']), $okFiles) && (empty($_SESSION['logged']) || $_SESSION['logged'] !== 'yes')) {
header( 'Location: login.php' );
exit;
Expand Down
11 changes: 11 additions & 0 deletions includes/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,16 @@
//set timezone offset, hours difference between your server's timezone and eastern
define('SERVER_TIMEZONE_OFFSET', 0);

//define a batch update "key" that a cronjob can pass to update scores automatically
//can be anything you want, as long as it can be sent as a get parameter on the URL
//NOTE: make your life easier and just use alpha-numerics w/out any special chars...
//NOTE: THE PAGE NAME IS CASE SENSEITVE TO BYPASS LOG-IN, IF THE CASE NOT MATCH, IT WILL REDIRECT TO LOGIN W/OUT UPDATING SCORES!
//example:
// curl -O 'http://www.yourdomain.com/getHtmlScores.php?BATCH_SCORE_UPDATE_KEY=yourRandomDefinedValueHere'
// wget 'http://www.yourdomain.com/getHtmlScores.php?BATCH_SCORE_UPDATE_KEY=yourRandomDefinedValueHere'
define('BATCH_SCORE_UPDATE_KEY', '1234567890abcdefghijklmnopqrstuvwxyz');
//enable or disable batch updates here
define('BATCH_SCORE_UPDATE_ENABLED', true);

// ***DO NOT EDIT ANYTHING BELOW THIS LINE***
error_reporting(E_ALL ^ E_NOTICE ^ E_STRICT);