Skip to content

Commit

Permalink
Changed St. Louis Rams to Los Angeles Rams
Browse files Browse the repository at this point in the history
  • Loading branch information
krothapigroup committed Jul 8, 2016
1 parent fdb898a commit 7df765e
Show file tree
Hide file tree
Showing 4 changed files with 120 additions and 138 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
# Change Log
All notable changes to this project will be documented in this file.

## 2.2.1 - 7/7/2016
### Changed
- Fixed for LA Rams

## 2.2.0 - 4/21/2016
### Changed
- Updated installer with 2016 schedule
Expand Down
133 changes: 63 additions & 70 deletions buildSchedule.php
Original file line number Diff line number Diff line change
@@ -1,70 +1,63 @@
<?php
require('includes/application_top.php');
error_reporting(E_ALL);
$weeks = 17;
$teamCodes = array(
'JAC' => 'JAX'
);
$schedule = array();

for ($week = 1; $week <= $weeks; $week++) {
$url = "http://www.nfl.com/ajax/scorestrip?season=".SEASON_YEAR."&seasonType=REG&week=".$week;
if ($xmlData = @file_get_contents($url)) {
$xml = simplexml_load_string($xmlData);
$json = json_encode($xml);
$games = json_decode($json, true);
} else {
die('Error getting schedule from nfl.com.');
}

//build scores array, to group teams and scores together in games
foreach ($games['gms']['g'] as $gameArray) {
$game = $gameArray['@attributes'];

//get game time (eastern)
$eid = $game['eid']; //date
$t = $game['t']; //time
$date = DateTime::createFromFormat('Ymds g:i a', $eid.' '.$t.' pm');
$gameTimeEastern = $date->format('Y-m-d H:i:00');

//get team codes
$away_team = $game['v'];
$home_team = $game['h'];
foreach ($teamCodes as $espnCode => $nflpCode) {
if ($away_team == $espnCode) $away_team = $nflpCode;
if ($home_team == $espnCode) $home_team = $nflpCode;
}

$schedule[] = array(
'weekNum' => $week,
'gameTimeEastern' => $gameTimeEastern,
'homeID' => $home_team,
'visitorID' => $away_team
);
}
}

//output to excel
$output = '<table>'."\n".
'<tr><td>weekNum</td><td>gameTimeEastern</td><td>homeID</td><td>visitorID</td></tr>'."\n";
for ($i = 0; $i < sizeof($schedule); $i++) {
$output .= '<tr><td>'.$schedule[$i]['weekNum'].'</td><td>'.$schedule[$i]['gameTimeEastern'].'</td><td>'.$schedule[$i]['homeID'].'</td><td>'.$schedule[$i]['visitorID'].'</td></tr>'."\n";
}
$output .= '</table>';

// fix for IE catching or PHP bug issue
header("Pragma: public");
header("Expires: 0"); // set expiration time
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
// browser must download file from server instead of cache

header('Content-Type: application/vnd.ms-excel;');
//header("Content-type: application/x-msexcel");
//header("Content-type: application/x-msdownload");
header("Content-Disposition: attachment; filename=nfl_schedule_".SEASON_YEAR.".xls");

echo $output;
//echo '<pre>';
//print_r($schedule);
//echo '</pre>';
exit;
<?php
require('includes/application_top.php');
error_reporting(E_ALL);
$weeks = 17;
$schedule = array();

for ($week = 1; $week <= $weeks; $week++) {
$url = "http://www.nfl.com/ajax/scorestrip?season=".SEASON_YEAR."&seasonType=REG&week=".$week;
if ($xmlData = @file_get_contents($url)) {
$xml = simplexml_load_string($xmlData);
$json = json_encode($xml);
$games = json_decode($json, true);
} else {
die('Error getting schedule from nfl.com.');
}

//build scores array, to group teams and scores together in games
foreach ($games['gms']['g'] as $gameArray) {
$game = $gameArray['@attributes'];

//get game time (eastern)
$eid = $game['eid']; //date
$t = $game['t']; //time
$date = DateTime::createFromFormat('Ymds g:i a', $eid.' '.$t.' pm');
$gameTimeEastern = $date->format('Y-m-d H:i:00');

//get team codes
$away_team = $game['v'];
$home_team = $game['h'];

$schedule[] = array(
'weekNum' => $week,
'gameTimeEastern' => $gameTimeEastern,
'homeID' => $home_team,
'visitorID' => $away_team
);
}
}

//output to excel
$output = '<table>'."\n".
'<tr><td>weekNum</td><td>gameTimeEastern</td><td>homeID</td><td>visitorID</td></tr>'."\n";
for ($i = 0; $i < sizeof($schedule); $i++) {
$output .= '<tr><td>'.$schedule[$i]['weekNum'].'</td><td>'.$schedule[$i]['gameTimeEastern'].'</td><td>'.$schedule[$i]['homeID'].'</td><td>'.$schedule[$i]['visitorID'].'</td></tr>'."\n";
}
$output .= '</table>';

// fix for IE catching or PHP bug issue
header("Pragma: public");
header("Expires: 0"); // set expiration time
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
// browser must download file from server instead of cache

header('Content-Type: application/vnd.ms-excel;');
//header("Content-type: application/x-msexcel");
//header("Content-type: application/x-msdownload");
header("Content-Disposition: attachment; filename=nfl_schedule_".SEASON_YEAR.".xls");

echo $output;
//echo '<pre>';
//print_r($schedule);
//echo '</pre>';
exit;
111 changes: 48 additions & 63 deletions getHtmlScores.php
Original file line number Diff line number Diff line change
@@ -1,63 +1,48 @@
<?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;
if ($xmlData = file_get_contents($url)) {
$xml = simplexml_load_string($xmlData);
$json = json_encode($xml);
$games = json_decode($json, true);
}

$teamCodes = array(
'GNB' => 'GB',
'JAC' => 'JAX',
'KAN' => 'KC',
'NWE' => 'NE',
'NOR' => 'NO',
'SDG' => 'SD',
'SFO' => 'SF',
'TAM' => 'TB'
);

//build scores array, to group teams and scores together in games
$scores = array();
foreach ($games['gms']['g'] as $gameArray) {
$game = $gameArray['@attributes'];
if ($game['q'] == 'F' || $game['q'] == 'FO') {
$overtime = (($game['q'] == 'FO') ? 1 : 0);
$away_team = $game['v'];
$home_team = $game['h'];
foreach ($teamCodes as $espnCode => $nflpCode) {
if ($away_team == $espnCode) $away_team = $nflpCode;
if ($home_team == $espnCode) $home_team = $nflpCode;
}
$away_score = (int)$game['vs'];
$home_score = (int)$game['hs'];

$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)
<?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;
if ($xmlData = file_get_contents($url)) {
$xml = simplexml_load_string($xmlData);
$json = json_encode($xml);
$games = json_decode($json, true);
}

//build scores array, to group teams and scores together in games
$scores = array();
foreach ($games['gms']['g'] as $gameArray) {
$game = $gameArray['@attributes'];
if ($game['q'] == 'F' || $game['q'] == 'FO') {
$overtime = (($game['q'] == 'FO') ? 1 : 0);
$away_team = $game['v'];
$home_team = $game['h'];
$away_score = (int)$game['vs'];
$home_score = (int)$game['hs'];

$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)
10 changes: 5 additions & 5 deletions install/install.sql
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,18 @@
Source Server : _localhost
Source Server Type : MySQL
Source Server Version : 50534
Source Server Version : 50542
Source Host : localhost
Source Database : nflpickem
Target Server Type : MySQL
Target Server Version : 50534
Target Server Version : 50542
File Encoding : utf-8
Date: 08/05/2015 23:35:16 PM
Date: 07/07/2016 19:37:35 PM
*/

SET NAMES utf8;
SET NAMES utf8mb4;
SET FOREIGN_KEY_CHECKS = 0;

-- ----------------------------
Expand Down Expand Up @@ -137,7 +137,7 @@ CREATE TABLE `nflp_teams` (
-- Records of `nflp_teams`
-- ----------------------------
BEGIN;
INSERT INTO `nflp_teams` VALUES ('ARI', '8', 'Arizona', 'Cardinals', null), ('ATL', '6', 'Atlanta', 'Falcons', null), ('BAL', '1', 'Baltimore', 'Ravens', null), ('BUF', '3', 'Buffalo', 'Bills', null), ('CAR', '6', 'Carolina', 'Panthers', null), ('CHI', '5', 'Chicago', 'Bears', null), ('CIN', '1', 'Cincinnati', 'Bengals', null), ('CLE', '1', 'Cleveland', 'Browns', null), ('DAL', '7', 'Dallas', 'Cowboys', null), ('DEN', '4', 'Denver', 'Broncos', null), ('DET', '5', 'Detroit', 'Lions', null), ('GB', '5', 'Green Bay', 'Packers', null), ('HOU', '2', 'Houston', 'Texans', null), ('IND', '2', 'Indianapolis', 'Colts', null), ('JAX', '2', 'Jacksonville', 'Jaguars', null), ('KC', '4', 'Kansas City', 'Chiefs', null), ('MIA', '3', 'Miami', 'Dolphins', null), ('MIN', '5', 'Minnesota', 'Vikings', null), ('NE', '3', 'New England', 'Patriots', null), ('NO', '6', 'New Orleans', 'Saints', null), ('NYG', '7', 'New York', 'Giants', 'NY Giants'), ('NYJ', '3', 'New York', 'Jets', 'NY Jets'), ('OAK', '4', 'Oakland', 'Raiders', null), ('PHI', '7', 'Philadelphia', 'Eagles', null), ('PIT', '1', 'Pittsburgh', 'Steelers', null), ('SD', '4', 'San Diego', 'Chargers', null), ('SEA', '8', 'Seattle', 'Seahawks', null), ('SF', '8', 'San Francisco', '49ers', null), ('STL', '8', 'St. Louis', 'Rams', null), ('TB', '6', 'Tampa Bay', 'Buccaneers', null), ('TEN', '2', 'Tennessee', 'Titans', null), ('WAS', '7', 'Washington', 'Redskins', null);
INSERT INTO `nflp_teams` VALUES ('ARI', '8', 'Arizona', 'Cardinals', null), ('ATL', '6', 'Atlanta', 'Falcons', null), ('BAL', '1', 'Baltimore', 'Ravens', null), ('BUF', '3', 'Buffalo', 'Bills', null), ('CAR', '6', 'Carolina', 'Panthers', null), ('CHI', '5', 'Chicago', 'Bears', null), ('CIN', '1', 'Cincinnati', 'Bengals', null), ('CLE', '1', 'Cleveland', 'Browns', null), ('DAL', '7', 'Dallas', 'Cowboys', null), ('DEN', '4', 'Denver', 'Broncos', null), ('DET', '5', 'Detroit', 'Lions', null), ('GB', '5', 'Green Bay', 'Packers', null), ('HOU', '2', 'Houston', 'Texans', null), ('IND', '2', 'Indianapolis', 'Colts', null), ('JAX', '2', 'Jacksonville', 'Jaguars', null), ('KC', '4', 'Kansas City', 'Chiefs', null), ('MIA', '3', 'Miami', 'Dolphins', null), ('MIN', '5', 'Minnesota', 'Vikings', null), ('NE', '3', 'New England', 'Patriots', null), ('NO', '6', 'New Orleans', 'Saints', null), ('NYG', '7', 'New York', 'Giants', 'NY Giants'), ('NYJ', '3', 'New York', 'Jets', 'NY Jets'), ('OAK', '4', 'Oakland', 'Raiders', null), ('PHI', '7', 'Philadelphia', 'Eagles', null), ('PIT', '1', 'Pittsburgh', 'Steelers', null), ('SD', '4', 'San Diego', 'Chargers', null), ('SEA', '8', 'Seattle', 'Seahawks', null), ('SF', '8', 'San Francisco', '49ers', null), ('LA', '8', 'Los Angeles', 'Rams', null), ('TB', '6', 'Tampa Bay', 'Buccaneers', null), ('TEN', '2', 'Tennessee', 'Titans', null), ('WAS', '7', 'Washington', 'Redskins', null);
COMMIT;

-- ----------------------------
Expand Down

0 comments on commit 7df765e

Please sign in to comment.