Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- //Betting Tools Extractor
- include 'functions.php';
- ////TESTING PURPOSES////
- ////////////////////////
- function ExtractGeneral(){
- //1. Login
- QueryLogin();
- //file_put_contents('extractor-log.txt', "Loggin succesfully\r\n", FILE_APPEND);
- //echo "Succesfully Login\n";
- //2. Tipster Table
- $url = 'http://www.bettingtools.co.uk/tipster-table/';
- $html = Query($url);
- $query = $html->query('//table[@id="imagetable3"]/tbody/tr');
- $races = [];
- $horses = [];
- $types = [];
- $odds = [];
- $hours = [];
- $tipsters = [];
- $profits = [];
- $fileOut = fopen(".".BT_PATH."tipsBT.csv", 'w');
- $cont = 0;
- $currMonth = date('n');
- foreach($query as $q)
- {
- //TESTING PURPOSES/////
- //$raceLink = '';
- //goto jump;
- ///////////////////////
- $tds = $q->getElementsByTagName("td");
- $row = [];
- $still = 0;
- $raceLink = '';
- foreach ($tds as $td) {
- $row[] = $td->nodeValue;
- $links = $td->childNodes;
- foreach ($links as $link) {
- if ($link->tagName == 'a' && $still == 0) {
- foreach ($link->attributes as $att){
- $still = 1;
- $raceLink = $att->nodeValue;
- }
- break;
- }
- if ($link->tagName == 'a' && $still == 1) {
- foreach ($link->attributes as $att){
- $still = 2;
- $profit = $att->nodeValue;
- $profit = htmlentities($profit, null, 'utf-8');
- }
- break;
- }
- }
- }
- if ($row[4] == 5 && $row[1] == 'H') {
- $hour = trim(substr($row[0], 3));
- if (is_numeric(strpos($row[2], 'Premium Tip')) == false && is_numeric(strpos($hour, ':')) == true) {
- $racehtml = Query('http://www.bettingtools.co.uk/'.$raceLink);
- $query = $racehtml->query('//table[@class="tipInfo"]/tr/td');
- $next = false;
- foreach($query as $q)
- {
- if ($next == true) {
- $race = $q->nodeValue;
- break;
- }
- elseif ($q->nodeValue == 'Competition:') {
- $next =true;
- }
- }
- $race1 = trim(substr($race, strpos($race, ' ')));
- if (is_numeric(strpos($race1, ':'))) {
- $race1 = trim(substr($race, 0, strpos($race, ' ')));
- }
- $race = $race1;
- if (is_numeric(strpos($race, '-'))) {
- $race = trim(substr($race, 0, strpos($race, '-')));
- }
- //////////CONDITIONATLS FOR RACES DUE TO TYPO ERRORS//////////
- if (is_numeric(strpos($race, 'Ascot')) && $currMonth == 6) {
- $race = 'Royal Ascot';
- }
- elseif ($race == 'Market') {
- $race = 'Market Rasen';
- }
- elseif ($race == 'Down') {
- $race = 'Down Royal';
- }
- elseif ($race == 'Ffos') {
- $race = 'Ffos Las';
- }
- $hours[] = $hour;
- $type = substr($row[2], strpos($row[2], '-> ')+3);
- $horse = substr($type, strpos($type, ' ')+1);
- $type = substr($type, 0, strpos($type, ' '));
- $type = strtolower($type);
- if ($type == 'e/w') {
- $type ='Each Way';
- }
- else{
- $type = 'Win';
- }
- $types[] = $type;
- $horse = htmlentities($horse, null, 'utf-8');
- $horse = str_replace(" ", "", $horse);
- $horses[] = html_entity_decode($horse);
- $tipsters[] = $row[3];
- $profits[] = $profit;
- $odds[] = $row[5];
- $races[] = $race;
- }
- }
- $cont++;
- }
- for ($i=0; $i < count($hours); $i++) {
- $csv = array_fill(0, 8, '');
- $csv[1] = $hours[$i];
- $csv[2] = $races[$i];
- $csv[3] = trim($horses[$i]);
- $csv[4] = $odds[$i];
- $csv[5] = $types[$i];
- $csv[6] = $tipsters[$i];
- $csv[7] = $profits[$i];
- fputcsv($fileOut, $csv);
- //file_put_contents('extractor-log.txt', "Write $i\r\n", FILE_APPEND);
- }
- }
- function SelectRaces(){
- ///Select races
- $tipsFile = fopen(".".BT_PATH."tipsBT.csv", "r");
- $optionsFile = fopen(".".BT_PATH."bettoolsOptions.csv", "r");
- $options = fgetcsv($optionsFile);
- fclose($optionsFile);
- $minOdds = $options[1];
- $maxOdds = $options[2];
- $numberOfBets = $options[4];
- if ($options[6] == 'checked') {
- $type = 'Win';
- }
- elseif ($options[7] == 'checked') {
- $type = 'Each Way';
- }
- else{
- $type = 'Both';
- }
- $betCounter = 0;
- $i = 0;
- $lastVenue = '';
- $lastHour = '';
- while (($row = fgetcsv($tipsFile)) != false) {
- $row[0] = '';
- if ($row[5] == $type || $type == 'Both') {
- if ($row[4] >= $minOdds && $row[4] <= $maxOdds) {
- if ($lastHour == $row[1] && $lastVenue == $row[2]) {
- if ($rows[$lastIndex][5] == 'Each Way' && $row[5] == 'Win') {
- $row[0] = 'checked';
- $rows[$lastIndex][0] = '';
- $lastIndex = $i;
- $lastHour = $row[1];
- $lastVenue = $row[2];
- }
- elseif ($rows[$lastIndex][5] == $row[5] && $row[4] < $rows[$lastIndex][4]) {
- $row[0] = 'checked';
- $rows[$lastIndex][0] = '';
- $lastIndex = $i;
- $lastHour = $row[1];
- $lastVenue = $row[2];
- }
- }
- else{
- if ($betCounter < $numberOfBets) {
- $row[0] = 'checked';
- $betCounter++;
- $lastIndex = $i;
- $lastHour = $row[1];
- $lastVenue = $row[2];
- //echo "Checked\n";
- }
- }
- }
- }
- $rows[$i] = $row;
- $i++;
- }
- //print_r($rows);
- fclose($tipsFile);
- $tipsFile = fopen(".".BT_PATH."tipsBT.csv", "w");
- for ($i=0; $i < count($rows); $i++) {
- fputcsv($tipsFile, $rows[$i]);
- }
- InitializeStatus($betCounter);
- $time = date('d-m-Y H:i');
- updateTime($time);
- }
- function ExtractTipster($url){
- //1. Login
- QueryLogin();
- //3. AndyHolding Tips
- $html = Query($url);
- $query = $html->query('//div[@id="table3"][1]/table/tbody/tr');
- $races = [];
- $horses = [];
- $types = [];
- $odds = [];
- $hours = [];
- $cont = 0;
- $fileOut = fopen(".".EX_PATH."tips.csv", 'w');
- $currMonth = date('n');
- foreach($query as $q)
- {
- $tds = $q->getElementsByTagName("td");
- $row = [];
- $still = 0;
- $raceLink = '';
- foreach ($tds as $td) {
- $row[] = $td->nodeValue;
- $links = $td->childNodes;
- foreach ($links as $link) {
- if ($link->tagName == 'a' && $still == 0) {
- foreach ($link->attributes as $att){
- $still = 1;
- $raceLink = $att->nodeValue;
- }
- break;
- }
- /*if ($link->tagName == 'a' && $still == 1) {
- foreach ($link->attributes as $att){
- $still = 2;
- $profit = $att->nodeValue;
- $profit = htmlentities($profit, null, 'utf-8');
- }
- break;
- }*/
- }
- }
- if ($row[1] == 'H') {
- $hour = trim(substr($row[0], 3));
- if(is_numeric(strpos($hour, ':'))){
- $racehtml = Query('http://www.bettingtools.co.uk/'.$raceLink);
- $query = $racehtml->query('//table[@class="tipInfo"]/tr/td');
- $next = false;
- foreach($query as $q)
- {
- if ($next == true) {
- $race = trim($q->nodeValue);
- break;
- }
- elseif ($q->nodeValue == 'Competition:') {
- $next =true;
- }
- }
- $race1 = trim(substr($race, strpos($race, ' ')));
- if (is_numeric(strpos($race1, ':'))) {
- $race1 = trim(substr($race, 0, strpos($race, ' ')));
- }
- $race = $race1;
- if (is_numeric(strpos($race, '-'))) {
- $race = trim(substr($race, 0, strpos($race, '-')));
- }
- //////////CONDITIONATLS FOR RACES DUE TO TYPO ERRORS//////////
- if (is_numeric(strpos($race, 'Ascot')) && $currMonth == 6) {
- $race = 'Royal Ascot';
- }
- elseif ($race == 'Market') {
- $race = 'Market Rasen';
- }
- elseif ($race == 'Down') {
- $race = 'Down Royal';
- }
- elseif ($race == 'Ffos') {
- $race = 'Ffos Las';
- }
- $hours[] = $hour;
- $type = substr($row[2], strpos($row[2], '-> ')+3);
- $types[] = substr($type, 0, strpos($type, ' '));
- $horse = substr($type, strpos($type, ' ')+1);
- $horse = htmlentities($horse, null, 'utf-8');
- $horse = str_replace(" ", "", $horse);
- $horses[] = html_entity_decode($horse);
- //$tipsters[] = $row[3];
- //$profits[] = $profit;
- $odds[] = $row[3];
- $races[] = $race;
- }
- }
- $cont++;
- //echo "$cont\n";
- }
- for ($i=0; $i < count($hours); $i++) {
- $csv = array_fill(0, 8, '');
- $csv[1] = $races[$i];
- $csv[2] = 'Today';
- $csv[3] = $hours[$i];
- $csv[4] = trim($horses[$i]);
- $csv[5] = '-';
- $csv[6] = $types[$i];
- $csv[7] = $odds[$i];
- fputcsv($fileOut, $csv);
- }
- fclose($fileOut);
- SelectRacesAccum($horses, $hours, $odds, $types, $races);
- }
- function SelectRacesAccum($horses, $hourss, $odds, $types, $venues){
- ///Select races
- $optionsFile = fopen("options.csv", "r");
- $options = fgetcsv($optionsFile);
- fclose($optionsFile);
- $timeOptions = explode(":", $options[2]);
- $hourOptions = $timeOptions[0];
- $minOptions = $timeOptions[1];
- $count = 0;
- if ($options[3] == 'checked') {
- $optType = 'Win';
- }
- elseif ($options[4] == 'checked') {
- $optType = 'Each Way';
- }
- else{
- $optType = 'Both';
- }
- $lastIndex = 0;
- for ($i=0; $i < count($horses); $i++) {
- if ($types[$i] == 'E/w' || $types[$i] == 'E/W') {
- $types[$i] = 'Each Way';
- }
- $checkbox[$i] = "";
- $hours1 = $hourss[$i];
- $hour = explode(":", $hours1)[0];
- $min = substr(explode(":", $hours1)[1], 0, 2);
- if ($hour > $hourOptions || ($hour == $hourOptions && $min >= $minOptions)) {
- if ($odds[$i] >= $options[6] && $odds[$i] <= $options[13]) {
- if ($types[$i] == $optType || $optType == "Both") {
- if ($hour > $lastHour || ($hour == $lastHour && ($min-$lastMinute >= 20))) {
- if ($count < $options[7]) {
- $lastHour = $hour;
- $lastMinute = $min;
- $lastIndex = $i;
- $checkbox[$i] = "checked";
- $count++;
- }
- }
- elseif ($venues[$i] == $venues[$lastIndex]) {
- if ($types[$lastIndex] == 'Each Way' && $types[$i] == 'Win') {
- $checkbox[$i] = "checked";
- $checkbox[$lastIndex] = "";
- $lastIndex = $i;
- }
- elseif ($types[$i] == $types[$lastIndex]) {
- if ($odds[$i] < $odds[$lastIndex]) {
- $checkbox[$i] = "checked";
- $checkbox[$lastIndex] = "";
- $lastIndex = $i;
- }
- }
- }
- }
- }
- }
- }
- $file = fopen(getcwd().EX_PATH.'tips.csv', 'w');
- $tipsForBetFile = fopen(getcwd().EX_PATH.'tipsForBets.csv', 'w');
- $tipPos = 0;
- for ($i=0; $i < count($horses); $i++) {
- $csv = array_fill(0, 8, '') ;
- $csv = [$checkbox[$i],$venues[$i],'Today',$hourss[$i],$horses[$i],'-',$types[$i],$odds[$i]];
- fputcsv($file, $csv);
- if ($checkbox[$i] == 'checked') {
- $tipPos ++;
- array_unshift($csv, $tipPos);
- fputcsv($tipsForBetFile, $csv);
- }
- }
- fclose($file);
- fclose($tipsForBetFile);
- $statusFile = fopen(getcwd().'/Betting_System/betStatus.csv','w');
- fputcsv($statusFile, [0,0,0,0]);
- fclose($statusFile);
- $csv = array();
- $newFile = fopen(getcwd().EX_PATH.'updateTipster.csv', 'w');
- $csv[0] = 'AndyHolding';
- date_default_timezone_set('Europe/London');
- $csv[1] = date('Y-m-d H:i');
- fputcsv($newFile, $csv);
- fclose($newFile);
- }
- function InitializeStatus($nTips){
- $betIds = array_fill(0, $nTips, '');
- $statusFile = fopen(getcwd().BT_PATH.'BTStatus.csv','w');
- for ($i=0; $i < count($betIds); $i++) {
- $csv = [];
- $csv[] = $betIds[$i];
- fputcsv($statusFile, $csv);
- }
- }
- function updateTime($time){
- $updateFile = getcwd().BT_PATH.'updateTime.txt';
- file_put_contents($updateFile, $time);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement