Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- ini_set('max_execution_time', 6000);
- ini_set('memory_limit','-1');
- // ----------------------------------------------------------------------------------------------------
- // - Display Errors
- // ----------------------------------------------------------------------------------------------------
- /*ini_set('display_errors', 'On');
- ini_set('html_errors', 0);
- // ----------------------------------------------------------------------------------------------------
- // - Error Reporting
- // ----------------------------------------------------------------------------------------------------
- error_reporting(-1);
- // ----------------------------------------------------------------------------------------------------
- // - Shutdown Handler
- // ----------------------------------------------------------------------------------------------------
- function ShutdownHandler()
- {
- if(@is_array($error = @error_get_last()))
- {
- return(@call_user_func_array('ErrorHandler', $error));
- };
- return(TRUE);
- };
- register_shutdown_function('ShutdownHandler');
- // ----------------------------------------------------------------------------------------------------
- // - Error Handler
- // ----------------------------------------------------------------------------------------------------
- function ErrorHandler($type, $message, $file, $line)
- {
- $_ERRORS = Array(
- 0x0001 => 'E_ERROR',
- 0x0002 => 'E_WARNING',
- 0x0004 => 'E_PARSE',
- 0x0008 => 'E_NOTICE',
- 0x0010 => 'E_CORE_ERROR',
- 0x0020 => 'E_CORE_WARNING',
- 0x0040 => 'E_COMPILE_ERROR',
- 0x0080 => 'E_COMPILE_WARNING',
- 0x0100 => 'E_USER_ERROR',
- 0x0200 => 'E_USER_WARNING',
- 0x0400 => 'E_USER_NOTICE',
- 0x0800 => 'E_STRICT',
- 0x1000 => 'E_RECOVERABLE_ERROR',
- 0x2000 => 'E_DEPRECATED',
- 0x4000 => 'E_USER_DEPRECATED'
- );
- if(!@is_string($name = @array_search($type, @array_flip($_ERRORS))))
- {
- $name = 'E_UNKNOWN';
- };
- return(print(@sprintf("%s Error in file \xBB%s\xAB at line %d: %s\n", $name, @basename($file), $line, $message)));
- };
- $old_error_handler = set_error_handler("ErrorHandler");
- */
- $host='localhost';
- $username="**";
- $pswrd="&&";
- $con = mysql_connect($host,$username,$pswrd);if (!$con){die('Could not connect: ' . mysql_error());}
- mysql_select_db("**",$con) or die('Error while selecting db');
- // This fetches the initial feed from the Pinnacle Sports API
- $feedUrl = 'https://api.pinnaclesports.com/v1/feed?sportid=29';
- //&leagueid=1728-1792-6416-1817
- // Set your credentials here, format = clientid:password from your account.
- $credentials = base64_encode("&&&&");
- // Build the header, the content-type can also be application/json if needed
- $header[] = 'Content-length: 0';
- $header[] = 'Content-type: application/xml';
- $header[] = 'Authorization: Basic ' . $credentials;
- // Set up a CURL channel.
- $httpChannel = curl_init();
- // Prime the channel
- curl_setopt($httpChannel, CURLOPT_URL, $feedUrl);
- curl_setopt($httpChannel, CURLOPT_RETURNTRANSFER, true);
- curl_setopt($httpChannel, CURLOPT_HTTPHEADER, $header);
- // Unless you have all the CA certificates installed in your trusted root authority, this should be left as false.
- curl_setopt($httpChannel, CURLOPT_SSL_VERIFYPEER, false);
- // This fetches the initial feed result. Next we will fetch the update using the fdTime value and the last URL parameter
- $initialFeed = curl_exec($httpChannel);
- // 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.
- $xmlDocument = simplexml_load_string($initialFeed);
- // Simple XML has now build an array of arrays or a dictionary of values, you may access this information by index or name.
- $feedTime = $xmlDocument->fd->fdTime;
- //echo "feed $feedTime";
- // Now we simply alter the URL with the last parameter and feed in the value of fdTime
- $feedUrl = 'https://api.pinnaclesports.com/v1/feed?sportid=29&last=' . $feedTime;
- //&leagueid=1728-1792-6416-1817
- // Now we can fetch the updates.
- $updates = curl_exec($httpChannel);
- //echo $updates;
- $league = $xmlDocument->xpath("//rsp/fd/sports/sport/leagues/league/id");
- $p=0;
- $starttime = microtime(true);
- foreach( $league as $l )
- {
- $l=$l[$p];
- //echo "League: $l<br>";
- $p++;
- $event = $xmlDocument->xpath("//rsp/fd/sports/sport/leagues/league/events/event");
- $i=0;
- foreach( $event as $ev )
- {
- $startDateTime = $xmlDocument->xpath("//rsp/fd/sports/sport/leagues/league/events/event/startDateTime");
- $startDateTime = $startDateTime[$i];
- $id = $xmlDocument->xpath("//rsp/fd/sports/sport/leagues/league/events/event/id");
- $id = $id[$i];
- $IsLive = $xmlDocument->xpath("//rsp/fd/sports/sport/leagues/league/events/event/IsLive");
- $IsLive = $IsLive[$i];
- $status = $xmlDocument->xpath("//rsp/fd/sports/sport/leagues/league/events/event/status");
- $status = $status[$i];
- $drawRotNum = $xmlDocument->xpath("//rsp/fd/sports/sport/leagues/league/events/event/drawRotNum");
- $drawRotNum = $drawRotNum[$i];
- $homeTeamtype=$xmlDocument->xpath("//rsp/fd/sports/sport/leagues/league/events/event/homeTeam//@type");
- $homeTeamtype=$homeTeamtype[$i];
- $homeTeam=$xmlDocument->xpath("//rsp/fd/sports/sport/leagues/league/events/event/homeTeam/name");
- $homeTeam=$homeTeam[$i];
- $homeTeamrotNum=$xmlDocument->xpath("//rsp/fd/sports/sport/leagues/league/events/event/homeTeam/rotNum");
- $homeTeamrotNum=$homeTeamrotNum[$i];
- $awayTeamtype=$xmlDocument->xpath("//rsp/fd/sports/sport/leagues/league/events/event/awayTeam//@type");
- $awayTeamtype=$awayTeamtype[$i];
- $awayTeam=$xmlDocument->xpath("//rsp/fd/sports/sport/leagues/league/events/event/awayTeam/name");
- $awayTeam=$awayTeam[$i];
- $awayTeamrotNum=$xmlDocument->xpath("//rsp/fd/sports/sport/leagues/league/events/event/awayTeam/rotNum");
- $awayTeamrotNum=$awayTeamrotNum[$i];
- $periodlineId=$xmlDocument->xpath("//rsp/fd/sports/sport/leagues/league/events/event/periods/period//@lineId");
- $periodlineId=$periodlineId[$i];
- $periodlinenumber=$xmlDocument->xpath("//rsp/fd/sports/sport/leagues/league/events/event/periods/period/number");
- $periodlinenumber=$periodlinenumber[$i];
- $periodlinedescription=$xmlDocument->xpath("//rsp/fd/sports/sport/leagues/league/events/event/periods/period/description");
- $periodlinedescription=$periodlinedescription[$i];
- $periodlinecutoffDateTime=$xmlDocument->xpath("//rsp/fd/sports/sport/leagues/league/events/event/periods/period/cutoffDateTime");
- $periodlinecutoffDateTime=$periodlinecutoffDateTime[$i];
- $spreadaltLineId=$xmlDocument->xpath("//rsp/fd/sports/sport/leagues/league/events/event/periods/period/spreads/spread//@altLineId");
- $spreadaltLineId=$spreadaltLineId[$i];
- $spreadawaySpread=$xmlDocument->xpath("//rsp/fd/sports/sport/leagues/league/events/event/periods/period/spreads/spread/awaySpread");
- $spreadawaySpread=$spreadawaySpread[$i];
- $spreadawayPrice=$xmlDocument->xpath("//rsp/fd/sports/sport/leagues/league/events/event/periods/period/spreads/spread/awayPrice");
- $spreadawayPrice=$spreadawayPrice[$i];
- $spreadhomeSpread=$xmlDocument->xpath("//rsp/fd/sports/sport/leagues/league/events/event/periods/period/spreads/spread/homeSpread");
- $spreadhomeSpread=$spreadhomeSpread[$i];
- $spreadhomePrice=$xmlDocument->xpath("//rsp/fd/sports/sport/leagues/league/events/event/periods/period/spreads/spread/homePrice");
- $spreadhomePrice=$spreadhomePrice[$i];
- $totalaltLineId=$xmlDocument->xpath("//rsp/fd/sports/sport/leagues/league/events/event/periods/period/totals/total//@altLineId");
- $totalaltLineId=$totalaltLineId[$i];
- $totalpoints=$xmlDocument->xpath("//rsp/fd/sports/sport/leagues/league/events/event/periods/period/totals/total/points");
- $totalpoints=$totalpoints[$i];
- $totaloverPrice=$xmlDocument->xpath("//rsp/fd/sports/sport/leagues/league/events/event/periods/period/totals/total/overPrice");
- $totaloverPrice=$totaloverPrice[$i];
- $totalunderPrice=$xmlDocument->xpath("//rsp/fd/sports/sport/leagues/league/events/event/periods/period/totals/total/underPrice");
- $totalunderPrice=$totalunderPrice[$i];
- $moneyLineawayPrice=$xmlDocument->xpath("//rsp/fd/sports/sport/leagues/league/events/event/periods/period/moneyLine/awayPrice");
- $moneyLineawayPrice=$moneyLineawayPrice[$i];
- $moneyLinehomePrice=$xmlDocument->xpath("//rsp/fd/sports/sport/leagues/league/events/event/periods/period/moneyLine/homePrice");
- $moneyLinehomePrice=$moneyLinehomePrice[$i];
- $moneyLinedrawPrice=$xmlDocument->xpath("//rsp/fd/sports/sport/leagues/league/events/event/periods/period/moneyLine/drawPrice");
- $moneyLinedrawPrice=$moneyLinedrawPrice[$i];
- $maxBetAmountspread=$xmlDocument->xpath("//rsp/fd/sports/sport/leagues/league/events/event/periods/period/maxBetAmount/spread");
- $maxBetAmountspread=$maxBetAmountspread[$i];
- $maxBetAmounttotalPoints=$xmlDocument->xpath("//rsp/fd/sports/sport/leagues/league/events/event/periods/period/maxBetAmount/totalPoints");
- $maxBetAmounttotalPoints=$maxBetAmounttotalPoints[$i];
- $maxBetAmountmoneyLine=$xmlDocument->xpath("//rsp/fd/sports/sport/leagues/league/events/event/periods/period/maxBetAmount/moneyLine");
- $maxBetAmountmoneyLine=$maxBetAmountmoneyLine[$i];
- $sql = "INSERT IGNORE INTO `_Soccer` (
- `league.id` ,
- `startDateTime` ,
- `id` ,
- `IsLive` ,
- `status` ,
- `drawRotNum` ,
- `homeTeam.type` ,
- `homeTeam.name` ,
- `homeTeam.rotNum` ,
- `awayTeam.type` ,
- `awayTeam.name` ,
- `awayTeam.rotNum` ,
- `period.lineId` ,
- `period.number` ,
- `period.description` ,
- `period.cutoffDateTime` ,
- `period.spread.altLineId` ,
- `period.spread.awaySpread` ,
- `period.spread.awayPrice` ,
- `period.spread.homeSpread` ,
- `period.spread.homePrice` ,
- `period.total.altLineId` ,
- `period.total.points` ,
- `period.total.overPrice` ,
- `period.total.underPrice` ,
- `period.moneyLine.awayPrice` ,
- `period.moneyLine.homePrice` ,
- `period.moneyLine.drawPrice` ,
- `period.maxBetAmount.spread` ,
- `period.maxBetAmount.totalPoints` ,
- `period.maxBetAmount.moneyLine`
- )
- VALUES (
- '$l',
- '$startDateTime',
- '$id',
- '$IsLive',
- '$status',
- '$drawRotNum',
- '$homeTeamtype',
- '$homeTeam',
- '$homeTeamrotNum',
- '$awayTeamtype',
- '$awayTeam',
- '$awayTeamrotNum',
- '$periodlineId',
- '$periodlinenumber',
- '$periodlinedescription',
- '$periodlinecutoffDateTime',
- '$spreadaltLineId',
- '$spreadawaySpread',
- '$spreadawayPrice',
- '$spreadhomeSpread',
- '$spreadhomePrice',
- '$totalaltLineId',
- '$totalpoints',
- '$totaloverPrice',
- '$totalunderPrice',
- '$moneyLineawayPrice',
- '$moneyLinehomePrice',
- '$moneyLinedrawPrice',
- '$maxBetAmountspread',
- '$maxBetAmounttotalPoints',
- '$maxBetAmountmoneyLine'
- )";
- $query = mysql_query($sql,$con);
- if(!$query){die('Could not insert values: ' . mysql_error());}
- $i++;
- }
- }
- $endtime = microtime(true);
- $duration = $endtime - $starttime;
- echo "Duration: $duration";
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement