Guest User

Untitled

a guest
Sep 5th, 2011
526
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.25 KB | None | 0 0
  1. <?php
  2.  
  3. function url_exists($url) {
  4. // Version 4.x supported
  5. $handle = curl_init($url);
  6. if (false === $handle)
  7. {
  8. return false;
  9. }
  10. curl_setopt($handle, CURLOPT_HEADER, false);
  11. curl_setopt($handle, CURLOPT_FAILONERROR, true); // this works
  12. curl_setopt($handle, CURLOPT_HTTPHEADER, Array("User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.15) Gecko/20080623 Firefox/2.0.0.15") ); // request as if Firefox
  13. curl_setopt($handle, CURLOPT_NOBODY, true);
  14. curl_setopt($handle, CURLOPT_RETURNTRANSFER, false);
  15. $connectable = curl_exec($handle);
  16. curl_close($handle);
  17. return $connectable;
  18. }
  19.  
  20. function convertteam($team) {
  21. $ret = "ERROR";
  22. $ct = array('DAL' => 'DAL', 'NYG' => 'NYG', 'PHI' => 'PHI', 'WSH' => 'WAS', 'ARI' => 'ARI', 'SF' => 'SFO', 'SEA' => 'SEA', 'STL' => 'STL', 'CHI' => 'CHI', 'DET' => 'DET', 'GB' => 'GNB', 'MIN' => 'MIN', 'ATL' => 'ATL','CAR' => 'CAR','NO' => 'NOR', 'TB' => 'TAM', 'TEN' => 'TEN', 'JAC' => 'JAC', 'IND' => 'IND', 'HOU' => 'HOU', 'PIT' => 'PIT', 'CLE' => 'CLE', 'CIN' => 'CIN', 'BAL' => 'BAL', 'SD' => 'SDG', 'OAK' => 'OAK', 'KC' => 'KAN', 'DEN' => 'DEN','NYJ' => 'NYJ','NE' => 'NWE', 'MIA' => 'MIA','BUF' => 'BUF');
  23. $ret = $ct[$team];
  24. return $ret;
  25. }
  26. ini_set("memory_limit", "256M");
  27. set_time_limit(2400);
  28. include_once('simple_html_dom.php');
  29. $connection = mysql_connect("localhost",$USER,$PASSWORD);
  30. $sql = "SELECT * from Games.NFLGames where startDate > '2003-08-20' and startDate < '2009-05-05'";
  31. $query = mysql_query($sql, $connection);
  32. while ($row = mysql_fetch_array($query, MYSQL_ASSOC)) {
  33. $url = "http://scores.espn.go.com/nfl/boxscore?gameId=" . $row['idNFL'];
  34. If (url_exists($url) == TRUE) {
  35. $dom = file_get_html($url);
  36. If(sizeof($dom->find('div[class="line-score-container]')) > 0) {
  37. $awayteam_scores = $dom->find('div[class="line-score-container]', 0)->find('table[class="linescore"]', 0)->find('tr', 1);
  38. $hometeam_scores = $dom->find('div[class="line-score-container]', 0)->find('table[class="linescore"]', 0)->find('tr', 2);
  39. $away_score['Team'] = convertteam(trim($awayteam_scores->find('td', 0)->plaintext));
  40. $away_score['1Q'] = trim($awayteam_scores->find('td', 1)->plaintext);
  41. $away_score['2Q'] = trim($awayteam_scores->find('td', 2)->plaintext);
  42. $away_score['3Q'] = trim($awayteam_scores->find('td', 3)->plaintext);
  43. $away_score['4Q'] = trim($awayteam_scores->find('td', 4)->plaintext);
  44. $home_score['Team'] = convertteam(trim($hometeam_scores->find('td', 0)->plaintext));
  45. $home_score['1Q'] = trim($hometeam_scores->find('td', 1)->plaintext);
  46. $home_score['2Q'] = trim($hometeam_scores->find('td', 2)->plaintext);
  47. $home_score['3Q'] = trim($hometeam_scores->find('td', 3)->plaintext);
  48. $home_score['4Q'] = trim($hometeam_scores->find('td', 4)->plaintext);
  49. If (sizeof($awayteam_scores->find('td')) == 7) {
  50. $away_score['OT'] = trim($awayteam_scores->find('td', 5)->plaintext);
  51. $away_score['TOT'] = trim($awayteam_scores->find('td', 6)->plaintext);
  52. $home_score['OT'] = trim($hometeam_scores->find('td', 5)->plaintext);
  53. $home_score['TOT'] = trim($hometeam_scores->find('td', 6)->plaintext);
  54. } else {
  55. $away_score['OT'] = "X";
  56. $away_score['TOT'] = trim($awayteam_scores->find('td', 5)->plaintext);
  57. $home_score['OT'] = "X";
  58. $home_score['TOT'] = trim($hometeam_scores->find('td', 5)->plaintext);
  59. }
  60. $SQL = "INSERT INTO `Results`.`NFLScores` (`idNFL`, `startDate`, `homeTeam`, `awayTeam`, `home_1Q`, `home_2Q`, `home_3Q`, `home_4Q`, `home_OT`, `home_TOT`, `away_1Q`, `away_2Q`, `away_3Q`, `away_4Q`, `away_OT`, `away_TOT`) VALUES ('" . $row['idNFL'] . "', '" . $row['startDate'] . "', '" . $row['homeTeam'] . "', '" . $row['awayTeam'] . "', '" . $home_score['1Q'] . "', '" . $home_score['2Q'] . "', '" . $home_score['3Q'] . "', '" . $home_score['4Q'] . "', '" . $home_score['OT'] . "', '" . $home_score['TOT'] . "', '" . $away_score['1Q'] . "', '" . $away_score['2Q'] . "', '" . $away_score['3Q'] . "', '" . $away_score['4Q'] . "', '" . $away_score['OT'] . "', '" . $away_score['TOT'] . "');";
  61. //echo $SQL . "<BR>";
  62. mysql_query($SQL, $connection);
  63. }
  64. if(sizeof($dom->find('div[class="story-container"]', 0)->find('div[class="mod-container mod-open mod-open-gamepack"]')) > 0) {
  65. $teamstats = $dom->find('div[class="story-container"]', 0)->find('div[class="mod-container mod-open mod-open-gamepack"]', 1)->find('table[class="mod-data"]', 0);
  66. $home_boxscore['1D'] = $teamstats->find('tr',1)->find('td', 1)->plaintext;
  67. //$home_boxscore['P1D'] = $teamstats->find('tr',2)->find('td', 1)->plaintext;
  68. //$home_boxscore['R1D'] = $teamstats->find('tr',3)->find('td', 1)->plaintext;
  69. //$home_boxscore['1DPen'] = $teamstats->find('tr',4)->find('td', 1)->plaintext;
  70. $home_3DETemp = $teamstats->find('tr',2)->find('td', 1)->plaintext;
  71. $home_3DETemp = explode("-", $home_3DETemp);
  72. $home_boxscore['3DE_S'] = $home_3DETemp[0];
  73. $home_boxscore['3DE_A'] = $home_3DETemp[1];
  74. $home_4DETemp = $teamstats->find('tr',3)->find('td', 1)->plaintext;
  75. $home_4DETemp = explode("-", $home_4DETemp);
  76. $home_boxscore['4DE_S'] = $home_4DETemp[0];
  77. $home_boxscore['4DE_A'] = $home_4DETemp[1];
  78. //$home_boxscore['TP'] = $teamstats->find('tr',7)->find('td', 1)->plaintext;
  79. $home_boxscore['TY'] = $teamstats->find('tr',4)->find('td', 1)->plaintext;
  80. $home_boxscore['Pass'] = $teamstats->find('tr',5)->find('td', 1)->plaintext;
  81. $home_PC = $teamstats->find('tr',6)->find('td', 1)->plaintext;
  82. $home_PC = explode("-", $home_PC);
  83. $home_boxscore['PASS_C'] = $home_PC[0];
  84. $home_boxscore['PASS_A'] = $home_PC[1];
  85. $home_boxscore['YPP'] = $teamstats->find('tr',7)->find('td', 1)->plaintext;
  86. $home_boxscore['Rush'] = $teamstats->find('tr',8)->find('td', 1)->plaintext;
  87. $home_boxscore['RushAtt'] = $teamstats->find('tr',9)->find('td', 1)->plaintext;
  88. $home_boxscore['YPR'] = $teamstats->find('tr',10)->find('td', 1)->plaintext;
  89. //$home_RZ = $teamstats->find('tr',15)->find('td', 1)->plaintext;
  90. //$home_RZ = explode("-", $home_RZ);
  91. //$home_boxscore['RZ_C'] = $home_RZ[0];
  92. //$home_boxscore['RZ_A'] = $home_RZ[1];
  93. $home_PEN = $teamstats->find('tr',11)->find('td', 1)->plaintext;
  94. $home_PEN = explode("-", $home_PEN);
  95. $home_boxscore['PEN_N'] = $home_PEN[0];
  96. $home_boxscore['PEN_YDS'] = $home_PEN[1];
  97. $home_boxscore['Turnovers'] = $teamstats->find('tr',12)->find('td', 1)->plaintext;
  98. $home_boxscore['FumblesLost'] = $teamstats->find('tr',13)->find('td', 1)->plaintext;
  99. $home_boxscore['IntThrown'] = $teamstats->find('tr',14)->find('td', 1)->plaintext;
  100. //$home_boxscore['DefSTTD'] = $teamstats->find('tr',20)->find('td', 1)->plaintext;
  101. $home_boxscore['Possession'] = $teamstats->find('tr',15)->find('td', 1)->plaintext;
  102. $away_boxscore['1D'] = $teamstats->find('tr',1)->find('td', 2)->plaintext;
  103. //$away_boxscore['P1D'] = $teamstats->find('tr',2)->find('td', 2)->plaintext;
  104. //$away_boxscore['R1D'] = $teamstats->find('tr',3)->find('td', 2)->plaintext;
  105. //$away_boxscore['1DPen'] = $teamstats->find('tr',4)->find('td', 2)->plaintext;
  106. $away_3DETemp = $teamstats->find('tr',2)->find('td', 2)->plaintext;
  107. $away_3DETemp = explode("-", $away_3DETemp);
  108. $away_boxscore['3DE_S'] = $away_3DETemp[0];
  109. $away_boxscore['3DE_A'] = $away_3DETemp[1];
  110. $away_4DETemp = $teamstats->find('tr',3)->find('td', 2)->plaintext;
  111. $away_4DETemp = explode("-", $away_4DETemp);
  112. $away_boxscore['4DE_S'] = $away_4DETemp[0];
  113. $away_boxscore['4DE_A'] = $away_4DETemp[1];
  114. //$away_boxscore['TP'] = $teamstats->find('tr',7)->find('td', 2)->plaintext;
  115. $away_boxscore['TY'] = $teamstats->find('tr',4)->find('td', 2)->plaintext;
  116. $away_boxscore['Pass'] = $teamstats->find('tr',5)->find('td', 2)->plaintext;
  117. $away_PC = $teamstats->find('tr',6)->find('td', 2)->plaintext;
  118. $away_PC = explode("-", $away_PC);
  119. $away_boxscore['PASS_C'] = $away_PC[0];
  120. $away_boxscore['PASS_A'] = $away_PC[1];
  121. $away_boxscore['YPP'] = $teamstats->find('tr',7)->find('td', 2)->plaintext;
  122. $away_boxscore['Rush'] = $teamstats->find('tr',8)->find('td', 2)->plaintext;
  123. $away_boxscore['RushAtt'] = $teamstats->find('tr',9)->find('td', 2)->plaintext;
  124. $away_boxscore['YPR'] = $teamstats->find('tr',10)->find('td', 2)->plaintext;
  125. //$away_RZ = $teamstats->find('tr',15)->find('td', 2)->plaintext;
  126. //$away_RZ = explode("-", $away_RZ);
  127. //$away_boxscore['RZ_C'] = $away_RZ[0];
  128. //$away_boxscore['RZ_A'] = $away_RZ[1];
  129. $away_PEN = $teamstats->find('tr',11)->find('td', 2)->plaintext;
  130. $away_PEN = explode("-", $away_PEN);
  131. $away_boxscore['PEN_N'] = $away_PEN[0];
  132. $away_boxscore['PEN_YDS'] = $away_PEN[1];
  133. $away_boxscore['Turnovers'] = $teamstats->find('tr',12)->find('td', 2)->plaintext;
  134. $away_boxscore['FumblesLost'] = $teamstats->find('tr',13)->find('td', 2)->plaintext;
  135. $away_boxscore['IntThrown'] = $teamstats->find('tr',14)->find('td', 2)->plaintext;
  136. //$away_boxscore['DefSTTD'] = $teamstats->find('tr',20)->find('td', 2)->plaintext;
  137. $away_boxscore['Possession'] = $teamstats->find('tr',15)->find('td', 2)->plaintext;
  138. $SQL = "INSERT INTO `Results`.`NFLBoxscore` (`idNFL`, `startDate`, `team`, `HomeAway`, `FirstDowns`, `Efficiency3D_S`, `Efficiency3D_A`, `Efficiency4D_S`, `Efficiency4D_A`, `TotalYards`, `Passing`, `Passing_Comp`, `Passing_Att`, `YardsPerPass`, `Rushing`, `Rushing_Att`, `YardsPerRush`, `Penalties_Number`, `Penalties_Yards`, `Turnovers`, `FumblesLost`, `InterceptionsThrown`, `Possession`) VALUES ('" . $row['idNFL'] . "', '" . $row['startDate'] . "', '" . $row['awayTeam'] . "', 'A', '" . $away_boxscore['1D'] . "', '" . $away_boxscore['3DE_S'] . "', '" . $away_boxscore['3DE_A'] . "', '" . $away_boxscore['4DE_S'] . "', '" . $away_boxscore['4DE_A'] . "', '" . $away_boxscore['TY'] . "', '" . $away_boxscore['Pass'] . "', '" . $away_boxscore['PASS_C'] . "', '" . $away_boxscore['PASS_A'] . "', '" . $away_boxscore['YPP'] . "', '" . $away_boxscore['Rush'] . "', '" . $away_boxscore['RushAtt'] . "', '" . $away_boxscore['YPR'] . "', '" . $away_boxscore['PEN_N'] . "', '" . $away_boxscore['PEN_YDS'] . "', '" . $away_boxscore['Turnovers'] . "', '" . $away_boxscore['FumblesLost'] . "', '" . $away_boxscore['IntThrown'] . "', '" . $away_boxscore['Possession'] . "');";
  139. //echo $SQL . "<BR>";
  140. mysql_query($SQL, $connection);
  141. $SQL = "INSERT INTO `Results`.`NFLBoxscore` (`idNFL`, `startDate`, `team`, `HomeAway`, `FirstDowns`, `Efficiency3D_S`, `Efficiency3D_A`, `Efficiency4D_S`, `Efficiency4D_A`, `TotalYards`, `Passing`, `Passing_Comp`, `Passing_Att`, `YardsPerPass`, `Rushing`, `Rushing_Att`, `YardsPerRush`, `Penalties_Number`, `Penalties_Yards`, `Turnovers`, `FumblesLost`, `InterceptionsThrown`, `Possession`) VALUES ('" . $row['idNFL'] . "', '" . $row['startDate'] . "', '" . $row['awayTeam'] . "', 'A', '" . $home_boxscore['1D'] . "', '" . $home_boxscore['3DE_S'] . "', '" . $home_boxscore['3DE_A'] . "', '" . $home_boxscore['4DE_S'] . "', '" . $home_boxscore['4DE_A'] . "', '" . $home_boxscore['TY'] . "', '" . $home_boxscore['Pass'] . "', '" . $home_boxscore['PASS_C'] . "', '" . $home_boxscore['PASS_A'] . "', '" . $home_boxscore['YPP'] . "', '" . $home_boxscore['Rush'] . "', '" . $home_boxscore['RushAtt'] . "', '" . $home_boxscore['YPR'] . "', '" . $home_boxscore['PEN_N'] . "', '" . $home_boxscore['PEN_YDS'] . "', '" . $home_boxscore['Turnovers'] . "', '" . $home_boxscore['FumblesLost'] . "', '" . $home_boxscore['IntThrown'] . "', '" . $home_boxscore['Possession'] . "');";
  142. mysql_query($SQL, $connection);
  143. }
  144. $dom->clear();
  145. unset($dom);
  146. }
  147. }
  148. ?>
Advertisement
Add Comment
Please, Sign In to add comment