Advertisement
Guest User

Untitled

a guest
Aug 1st, 2014
266
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.69 KB | None | 0 0
  1. <?php
  2. ini_set('max_execution_time', 6000);
  3. ini_set('memory_limit','-1');
  4. // ----------------------------------------------------------------------------------------------------
  5. // - Display Errors
  6. // ----------------------------------------------------------------------------------------------------
  7. /*ini_set('display_errors', 'On');
  8. ini_set('html_errors', 0);
  9.  
  10. // ----------------------------------------------------------------------------------------------------
  11. // - Error Reporting
  12. // ----------------------------------------------------------------------------------------------------
  13. error_reporting(-1);
  14.  
  15. // ----------------------------------------------------------------------------------------------------
  16. // - Shutdown Handler
  17. // ----------------------------------------------------------------------------------------------------
  18. function ShutdownHandler()
  19. {
  20. if(@is_array($error = @error_get_last()))
  21. {
  22. return(@call_user_func_array('ErrorHandler', $error));
  23. };
  24.  
  25. return(TRUE);
  26. };
  27.  
  28. register_shutdown_function('ShutdownHandler');
  29.  
  30. // ----------------------------------------------------------------------------------------------------
  31. // - Error Handler
  32. // ----------------------------------------------------------------------------------------------------
  33. function ErrorHandler($type, $message, $file, $line)
  34. {
  35. $_ERRORS = Array(
  36. 0x0001 => 'E_ERROR',
  37. 0x0002 => 'E_WARNING',
  38. 0x0004 => 'E_PARSE',
  39. 0x0008 => 'E_NOTICE',
  40. 0x0010 => 'E_CORE_ERROR',
  41. 0x0020 => 'E_CORE_WARNING',
  42. 0x0040 => 'E_COMPILE_ERROR',
  43. 0x0080 => 'E_COMPILE_WARNING',
  44. 0x0100 => 'E_USER_ERROR',
  45. 0x0200 => 'E_USER_WARNING',
  46. 0x0400 => 'E_USER_NOTICE',
  47. 0x0800 => 'E_STRICT',
  48. 0x1000 => 'E_RECOVERABLE_ERROR',
  49. 0x2000 => 'E_DEPRECATED',
  50. 0x4000 => 'E_USER_DEPRECATED'
  51. );
  52.  
  53. if(!@is_string($name = @array_search($type, @array_flip($_ERRORS))))
  54. {
  55. $name = 'E_UNKNOWN';
  56. };
  57.  
  58. return(print(@sprintf("%s Error in file \xBB%s\xAB at line %d: %s\n", $name, @basename($file), $line, $message)));
  59. };
  60.  
  61. $old_error_handler = set_error_handler("ErrorHandler");
  62. */
  63.  
  64. $host='localhost';
  65. $username="**";
  66. $pswrd="&&";
  67. $con = mysql_connect($host,$username,$pswrd);if (!$con){die('Could not connect: ' . mysql_error());}
  68. mysql_select_db("**",$con) or die('Error while selecting db');
  69.  
  70. // This fetches the initial feed from the Pinnacle Sports API
  71. $feedUrl = 'https://api.pinnaclesports.com/v1/feed?sportid=29';
  72. //&leagueid=1728-1792-6416-1817
  73. // Set your credentials here, format = clientid:password from your account.
  74. $credentials = base64_encode("&&&&");
  75.  
  76. // Build the header, the content-type can also be application/json if needed
  77. $header[] = 'Content-length: 0';
  78. $header[] = 'Content-type: application/xml';
  79. $header[] = 'Authorization: Basic ' . $credentials;
  80.  
  81. // Set up a CURL channel.
  82. $httpChannel = curl_init();
  83. // Prime the channel
  84. curl_setopt($httpChannel, CURLOPT_URL, $feedUrl);
  85. curl_setopt($httpChannel, CURLOPT_RETURNTRANSFER, true);
  86. curl_setopt($httpChannel, CURLOPT_HTTPHEADER, $header);
  87. // Unless you have all the CA certificates installed in your trusted root authority, this should be left as false.
  88. curl_setopt($httpChannel, CURLOPT_SSL_VERIFYPEER, false);
  89.  
  90. // This fetches the initial feed result. Next we will fetch the update using the fdTime value and the last URL parameter
  91. $initialFeed = curl_exec($httpChannel);
  92.  
  93.  
  94. // You need to pick an XML library that is suitable for you, in this case i am using the built-in simple XML feature of PHP.
  95. $xmlDocument = simplexml_load_string($initialFeed);
  96. // Simple XML has now build an array of arrays or a dictionary of values, you may access this information by index or name.
  97. $feedTime = $xmlDocument->fd->fdTime;
  98. //echo "feed $feedTime";
  99.  
  100. // Now we simply alter the URL with the last parameter and feed in the value of fdTime
  101. $feedUrl = 'https://api.pinnaclesports.com/v1/feed?sportid=29&last=' . $feedTime;
  102. //&leagueid=1728-1792-6416-1817
  103. // Now we can fetch the updates.
  104. $updates = curl_exec($httpChannel);
  105. //echo $updates;
  106.  
  107.  
  108.  
  109. $league = $xmlDocument->xpath("//rsp/fd/sports/sport/leagues/league/id");
  110. $p=0;
  111. $starttime = microtime(true);
  112. foreach( $league as $l )
  113. {
  114. $l=$l[$p];
  115. //echo "League: $l<br>";
  116. $p++;
  117.  
  118. $event = $xmlDocument->xpath("//rsp/fd/sports/sport/leagues/league/events/event");
  119. $i=0;
  120. foreach( $event as $ev )
  121. {
  122. $startDateTime = $xmlDocument->xpath("//rsp/fd/sports/sport/leagues/league/events/event/startDateTime");
  123. $startDateTime = $startDateTime[$i];
  124. $id = $xmlDocument->xpath("//rsp/fd/sports/sport/leagues/league/events/event/id");
  125. $id = $id[$i];
  126. $IsLive = $xmlDocument->xpath("//rsp/fd/sports/sport/leagues/league/events/event/IsLive");
  127. $IsLive = $IsLive[$i];
  128. $status = $xmlDocument->xpath("//rsp/fd/sports/sport/leagues/league/events/event/status");
  129. $status = $status[$i];
  130. $drawRotNum = $xmlDocument->xpath("//rsp/fd/sports/sport/leagues/league/events/event/drawRotNum");
  131. $drawRotNum = $drawRotNum[$i];
  132.  
  133. $homeTeamtype=$xmlDocument->xpath("//rsp/fd/sports/sport/leagues/league/events/event/homeTeam//@type");
  134. $homeTeamtype=$homeTeamtype[$i];
  135. $homeTeam=$xmlDocument->xpath("//rsp/fd/sports/sport/leagues/league/events/event/homeTeam/name");
  136. $homeTeam=$homeTeam[$i];
  137. $homeTeamrotNum=$xmlDocument->xpath("//rsp/fd/sports/sport/leagues/league/events/event/homeTeam/rotNum");
  138. $homeTeamrotNum=$homeTeamrotNum[$i];
  139.  
  140. $awayTeamtype=$xmlDocument->xpath("//rsp/fd/sports/sport/leagues/league/events/event/awayTeam//@type");
  141. $awayTeamtype=$awayTeamtype[$i];
  142. $awayTeam=$xmlDocument->xpath("//rsp/fd/sports/sport/leagues/league/events/event/awayTeam/name");
  143. $awayTeam=$awayTeam[$i];
  144. $awayTeamrotNum=$xmlDocument->xpath("//rsp/fd/sports/sport/leagues/league/events/event/awayTeam/rotNum");
  145. $awayTeamrotNum=$awayTeamrotNum[$i];
  146.  
  147. $periodlineId=$xmlDocument->xpath("//rsp/fd/sports/sport/leagues/league/events/event/periods/period//@lineId");
  148. $periodlineId=$periodlineId[$i];
  149. $periodlinenumber=$xmlDocument->xpath("//rsp/fd/sports/sport/leagues/league/events/event/periods/period/number");
  150. $periodlinenumber=$periodlinenumber[$i];
  151. $periodlinedescription=$xmlDocument->xpath("//rsp/fd/sports/sport/leagues/league/events/event/periods/period/description");
  152. $periodlinedescription=$periodlinedescription[$i];
  153. $periodlinecutoffDateTime=$xmlDocument->xpath("//rsp/fd/sports/sport/leagues/league/events/event/periods/period/cutoffDateTime");
  154. $periodlinecutoffDateTime=$periodlinecutoffDateTime[$i];
  155.  
  156.  
  157. $spreadaltLineId=$xmlDocument->xpath("//rsp/fd/sports/sport/leagues/league/events/event/periods/period/spreads/spread//@altLineId");
  158. $spreadaltLineId=$spreadaltLineId[$i];
  159.  
  160. $spreadawaySpread=$xmlDocument->xpath("//rsp/fd/sports/sport/leagues/league/events/event/periods/period/spreads/spread/awaySpread");
  161. $spreadawaySpread=$spreadawaySpread[$i];
  162.  
  163. $spreadawayPrice=$xmlDocument->xpath("//rsp/fd/sports/sport/leagues/league/events/event/periods/period/spreads/spread/awayPrice");
  164. $spreadawayPrice=$spreadawayPrice[$i];
  165.  
  166. $spreadhomeSpread=$xmlDocument->xpath("//rsp/fd/sports/sport/leagues/league/events/event/periods/period/spreads/spread/homeSpread");
  167. $spreadhomeSpread=$spreadhomeSpread[$i];
  168.  
  169. $spreadhomePrice=$xmlDocument->xpath("//rsp/fd/sports/sport/leagues/league/events/event/periods/period/spreads/spread/homePrice");
  170. $spreadhomePrice=$spreadhomePrice[$i];
  171.  
  172. $totalaltLineId=$xmlDocument->xpath("//rsp/fd/sports/sport/leagues/league/events/event/periods/period/totals/total//@altLineId");
  173. $totalaltLineId=$totalaltLineId[$i];
  174.  
  175. $totalpoints=$xmlDocument->xpath("//rsp/fd/sports/sport/leagues/league/events/event/periods/period/totals/total/points");
  176. $totalpoints=$totalpoints[$i];
  177.  
  178. $totaloverPrice=$xmlDocument->xpath("//rsp/fd/sports/sport/leagues/league/events/event/periods/period/totals/total/overPrice");
  179. $totaloverPrice=$totaloverPrice[$i];
  180.  
  181. $totalunderPrice=$xmlDocument->xpath("//rsp/fd/sports/sport/leagues/league/events/event/periods/period/totals/total/underPrice");
  182. $totalunderPrice=$totalunderPrice[$i];
  183.  
  184.  
  185. $moneyLineawayPrice=$xmlDocument->xpath("//rsp/fd/sports/sport/leagues/league/events/event/periods/period/moneyLine/awayPrice");
  186. $moneyLineawayPrice=$moneyLineawayPrice[$i];
  187.  
  188. $moneyLinehomePrice=$xmlDocument->xpath("//rsp/fd/sports/sport/leagues/league/events/event/periods/period/moneyLine/homePrice");
  189. $moneyLinehomePrice=$moneyLinehomePrice[$i];
  190.  
  191. $moneyLinedrawPrice=$xmlDocument->xpath("//rsp/fd/sports/sport/leagues/league/events/event/periods/period/moneyLine/drawPrice");
  192. $moneyLinedrawPrice=$moneyLinedrawPrice[$i];
  193.  
  194.  
  195. $maxBetAmountspread=$xmlDocument->xpath("//rsp/fd/sports/sport/leagues/league/events/event/periods/period/maxBetAmount/spread");
  196. $maxBetAmountspread=$maxBetAmountspread[$i];
  197.  
  198. $maxBetAmounttotalPoints=$xmlDocument->xpath("//rsp/fd/sports/sport/leagues/league/events/event/periods/period/maxBetAmount/totalPoints");
  199. $maxBetAmounttotalPoints=$maxBetAmounttotalPoints[$i];
  200.  
  201. $maxBetAmountmoneyLine=$xmlDocument->xpath("//rsp/fd/sports/sport/leagues/league/events/event/periods/period/maxBetAmount/moneyLine");
  202. $maxBetAmountmoneyLine=$maxBetAmountmoneyLine[$i];
  203.  
  204. $sql = "INSERT IGNORE INTO `_Soccer` (
  205. `league.id` ,
  206. `startDateTime` ,
  207. `id` ,
  208. `IsLive` ,
  209. `status` ,
  210. `drawRotNum` ,
  211.  
  212. `homeTeam.type` ,
  213. `homeTeam.name` ,
  214. `homeTeam.rotNum` ,
  215.  
  216. `awayTeam.type` ,
  217. `awayTeam.name` ,
  218. `awayTeam.rotNum` ,
  219.  
  220. `period.lineId` ,
  221. `period.number` ,
  222. `period.description` ,
  223. `period.cutoffDateTime` ,
  224.  
  225. `period.spread.altLineId` ,
  226. `period.spread.awaySpread` ,
  227. `period.spread.awayPrice` ,
  228. `period.spread.homeSpread` ,
  229. `period.spread.homePrice` ,
  230.  
  231. `period.total.altLineId` ,
  232. `period.total.points` ,
  233. `period.total.overPrice` ,
  234. `period.total.underPrice` ,
  235.  
  236. `period.moneyLine.awayPrice` ,
  237. `period.moneyLine.homePrice` ,
  238. `period.moneyLine.drawPrice` ,
  239.  
  240. `period.maxBetAmount.spread` ,
  241. `period.maxBetAmount.totalPoints` ,
  242. `period.maxBetAmount.moneyLine`
  243. )
  244. VALUES (
  245. '$l',
  246. '$startDateTime',
  247. '$id',
  248. '$IsLive',
  249. '$status',
  250. '$drawRotNum',
  251.  
  252. '$homeTeamtype',
  253. '$homeTeam',
  254. '$homeTeamrotNum',
  255.  
  256. '$awayTeamtype',
  257. '$awayTeam',
  258. '$awayTeamrotNum',
  259.  
  260. '$periodlineId',
  261. '$periodlinenumber',
  262. '$periodlinedescription',
  263. '$periodlinecutoffDateTime',
  264.  
  265. '$spreadaltLineId',
  266. '$spreadawaySpread',
  267. '$spreadawayPrice',
  268. '$spreadhomeSpread',
  269. '$spreadhomePrice',
  270.  
  271. '$totalaltLineId',
  272. '$totalpoints',
  273. '$totaloverPrice',
  274. '$totalunderPrice',
  275.  
  276. '$moneyLineawayPrice',
  277. '$moneyLinehomePrice',
  278. '$moneyLinedrawPrice',
  279.  
  280. '$maxBetAmountspread',
  281. '$maxBetAmounttotalPoints',
  282. '$maxBetAmountmoneyLine'
  283. )";
  284. $query = mysql_query($sql,$con);
  285. if(!$query){die('Could not insert values: ' . mysql_error());}
  286.  
  287. $i++;
  288. }
  289. }
  290. $endtime = microtime(true);
  291. $duration = $endtime - $starttime;
  292.  
  293. echo "Duration: $duration";
  294. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement