Advertisement
Guest User

Untitled

a guest
Jul 23rd, 2016
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.24 KB | None | 0 0
  1. <?php
  2.  
  3. //Betting Tools Extractor
  4.  
  5. include 'functions.php';
  6.  
  7. ////TESTING PURPOSES////
  8.  
  9. ////////////////////////
  10. function ExtractGeneral(){
  11. //1. Login
  12.  
  13. QueryLogin();
  14. //file_put_contents('extractor-log.txt', "Loggin succesfully\r\n", FILE_APPEND);
  15. //echo "Succesfully Login\n";
  16. //2. Tipster Table
  17. $url = 'http://www.bettingtools.co.uk/tipster-table/';
  18. $html = Query($url);
  19.  
  20. $query = $html->query('//table[@id="imagetable3"]/tbody/tr');
  21.  
  22. $races = [];
  23. $horses = [];
  24. $types = [];
  25. $odds = [];
  26. $hours = [];
  27. $tipsters = [];
  28. $profits = [];
  29.  
  30. $fileOut = fopen(".".BT_PATH."tipsBT.csv", 'w');
  31.  
  32. $cont = 0;
  33.  
  34. $currMonth = date('n');
  35. foreach($query as $q)
  36. {
  37.  
  38. //TESTING PURPOSES/////
  39. //$raceLink = '';
  40. //goto jump;
  41. ///////////////////////
  42.  
  43. $tds = $q->getElementsByTagName("td");
  44.  
  45. $row = [];
  46. $still = 0;
  47. $raceLink = '';
  48. foreach ($tds as $td) {
  49.  
  50. $row[] = $td->nodeValue;
  51. $links = $td->childNodes;
  52. foreach ($links as $link) {
  53.  
  54. if ($link->tagName == 'a' && $still == 0) {
  55. foreach ($link->attributes as $att){
  56. $still = 1;
  57. $raceLink = $att->nodeValue;
  58. }
  59. break;
  60. }
  61. if ($link->tagName == 'a' && $still == 1) {
  62. foreach ($link->attributes as $att){
  63. $still = 2;
  64. $profit = $att->nodeValue;
  65. $profit = htmlentities($profit, null, 'utf-8');
  66. }
  67. break;
  68. }
  69. }
  70. }
  71.  
  72. if ($row[4] == 5 && $row[1] == 'H') {
  73. $hour = trim(substr($row[0], 3));
  74. if (is_numeric(strpos($row[2], 'Premium Tip')) == false && is_numeric(strpos($hour, ':')) == true) {
  75.  
  76. $racehtml = Query('http://www.bettingtools.co.uk/'.$raceLink);
  77. $query = $racehtml->query('//table[@class="tipInfo"]/tr/td');
  78.  
  79. $next = false;
  80. foreach($query as $q)
  81. {
  82. if ($next == true) {
  83. $race = $q->nodeValue;
  84. break;
  85. }
  86. elseif ($q->nodeValue == 'Competition:') {
  87. $next =true;
  88. }
  89. }
  90.  
  91. $race1 = trim(substr($race, strpos($race, ' ')));
  92. if (is_numeric(strpos($race1, ':'))) {
  93. $race1 = trim(substr($race, 0, strpos($race, ' ')));
  94. }
  95. $race = $race1;
  96.  
  97. if (is_numeric(strpos($race, '-'))) {
  98. $race = trim(substr($race, 0, strpos($race, '-')));
  99. }
  100.  
  101. //////////CONDITIONATLS FOR RACES DUE TO TYPO ERRORS//////////
  102. if (is_numeric(strpos($race, 'Ascot')) && $currMonth == 6) {
  103. $race = 'Royal Ascot';
  104. }
  105. elseif ($race == 'Market') {
  106. $race = 'Market Rasen';
  107. }
  108. elseif ($race == 'Down') {
  109. $race = 'Down Royal';
  110. }
  111. elseif ($race == 'Ffos') {
  112. $race = 'Ffos Las';
  113. }
  114.  
  115.  
  116. $hours[] = $hour;
  117. $type = substr($row[2], strpos($row[2], '-> ')+3);
  118. $horse = substr($type, strpos($type, ' ')+1);
  119. $type = substr($type, 0, strpos($type, ' '));
  120.  
  121. $type = strtolower($type);
  122. if ($type == 'e/w') {
  123. $type ='Each Way';
  124. }
  125. else{
  126. $type = 'Win';
  127. }
  128. $types[] = $type;
  129.  
  130. $horse = htmlentities($horse, null, 'utf-8');
  131. $horse = str_replace("&nbsp;", "", $horse);
  132. $horses[] = html_entity_decode($horse);
  133. $tipsters[] = $row[3];
  134. $profits[] = $profit;
  135.  
  136. $odds[] = $row[5];
  137. $races[] = $race;
  138. }
  139.  
  140. }
  141.  
  142. $cont++;
  143.  
  144. }
  145.  
  146.  
  147. for ($i=0; $i < count($hours); $i++) {
  148. $csv = array_fill(0, 8, '');
  149.  
  150. $csv[1] = $hours[$i];
  151. $csv[2] = $races[$i];
  152. $csv[3] = trim($horses[$i]);
  153. $csv[4] = $odds[$i];
  154. $csv[5] = $types[$i];
  155. $csv[6] = $tipsters[$i];
  156. $csv[7] = $profits[$i];
  157.  
  158. fputcsv($fileOut, $csv);
  159. //file_put_contents('extractor-log.txt', "Write $i\r\n", FILE_APPEND);
  160. }
  161. }
  162.  
  163. function SelectRaces(){
  164. ///Select races
  165.  
  166. $tipsFile = fopen(".".BT_PATH."tipsBT.csv", "r");
  167. $optionsFile = fopen(".".BT_PATH."bettoolsOptions.csv", "r");
  168. $options = fgetcsv($optionsFile);
  169. fclose($optionsFile);
  170.  
  171. $minOdds = $options[1];
  172. $maxOdds = $options[2];
  173. $numberOfBets = $options[4];
  174.  
  175. if ($options[6] == 'checked') {
  176. $type = 'Win';
  177. }
  178. elseif ($options[7] == 'checked') {
  179. $type = 'Each Way';
  180. }
  181. else{
  182. $type = 'Both';
  183. }
  184.  
  185. $betCounter = 0;
  186. $i = 0;
  187. $lastVenue = '';
  188. $lastHour = '';
  189. while (($row = fgetcsv($tipsFile)) != false) {
  190.  
  191. $row[0] = '';
  192.  
  193. if ($row[5] == $type || $type == 'Both') {
  194. if ($row[4] >= $minOdds && $row[4] <= $maxOdds) {
  195.  
  196. if ($lastHour == $row[1] && $lastVenue == $row[2]) {
  197. if ($rows[$lastIndex][5] == 'Each Way' && $row[5] == 'Win') {
  198. $row[0] = 'checked';
  199. $rows[$lastIndex][0] = '';
  200. $lastIndex = $i;
  201. $lastHour = $row[1];
  202. $lastVenue = $row[2];
  203. }
  204. elseif ($rows[$lastIndex][5] == $row[5] && $row[4] < $rows[$lastIndex][4]) {
  205. $row[0] = 'checked';
  206. $rows[$lastIndex][0] = '';
  207. $lastIndex = $i;
  208. $lastHour = $row[1];
  209. $lastVenue = $row[2];
  210. }
  211. }
  212. else{
  213. if ($betCounter < $numberOfBets) {
  214. $row[0] = 'checked';
  215. $betCounter++;
  216. $lastIndex = $i;
  217. $lastHour = $row[1];
  218. $lastVenue = $row[2];
  219. //echo "Checked\n";
  220. }
  221. }
  222.  
  223. }
  224. }
  225.  
  226. $rows[$i] = $row;
  227. $i++;
  228. }
  229.  
  230. //print_r($rows);
  231.  
  232. fclose($tipsFile);
  233. $tipsFile = fopen(".".BT_PATH."tipsBT.csv", "w");
  234. for ($i=0; $i < count($rows); $i++) {
  235. fputcsv($tipsFile, $rows[$i]);
  236. }
  237.  
  238. InitializeStatus($betCounter);
  239. $time = date('d-m-Y H:i');
  240. updateTime($time);
  241. }
  242.  
  243. function ExtractTipster($url){
  244. //1. Login
  245.  
  246. QueryLogin();
  247.  
  248. //3. AndyHolding Tips
  249. $html = Query($url);
  250.  
  251. $query = $html->query('//div[@id="table3"][1]/table/tbody/tr');
  252.  
  253. $races = [];
  254. $horses = [];
  255. $types = [];
  256. $odds = [];
  257. $hours = [];
  258. $cont = 0;
  259.  
  260. $fileOut = fopen(".".EX_PATH."tips.csv", 'w');
  261.  
  262. $currMonth = date('n');
  263.  
  264. foreach($query as $q)
  265. {
  266.  
  267. $tds = $q->getElementsByTagName("td");
  268.  
  269. $row = [];
  270. $still = 0;
  271. $raceLink = '';
  272. foreach ($tds as $td) {
  273.  
  274. $row[] = $td->nodeValue;
  275. $links = $td->childNodes;
  276. foreach ($links as $link) {
  277.  
  278. if ($link->tagName == 'a' && $still == 0) {
  279. foreach ($link->attributes as $att){
  280. $still = 1;
  281. $raceLink = $att->nodeValue;
  282. }
  283. break;
  284. }
  285. /*if ($link->tagName == 'a' && $still == 1) {
  286. foreach ($link->attributes as $att){
  287. $still = 2;
  288. $profit = $att->nodeValue;
  289. $profit = htmlentities($profit, null, 'utf-8');
  290. }
  291. break;
  292. }*/
  293. }
  294. }
  295.  
  296. if ($row[1] == 'H') {
  297.  
  298. $hour = trim(substr($row[0], 3));
  299. if(is_numeric(strpos($hour, ':'))){
  300. $racehtml = Query('http://www.bettingtools.co.uk/'.$raceLink);
  301. $query = $racehtml->query('//table[@class="tipInfo"]/tr/td');
  302.  
  303. $next = false;
  304. foreach($query as $q)
  305. {
  306. if ($next == true) {
  307. $race = trim($q->nodeValue);
  308. break;
  309. }
  310. elseif ($q->nodeValue == 'Competition:') {
  311. $next =true;
  312. }
  313. }
  314.  
  315. $race1 = trim(substr($race, strpos($race, ' ')));
  316.  
  317. if (is_numeric(strpos($race1, ':'))) {
  318. $race1 = trim(substr($race, 0, strpos($race, ' ')));
  319. }
  320. $race = $race1;
  321.  
  322. if (is_numeric(strpos($race, '-'))) {
  323. $race = trim(substr($race, 0, strpos($race, '-')));
  324. }
  325.  
  326. //////////CONDITIONATLS FOR RACES DUE TO TYPO ERRORS//////////
  327. if (is_numeric(strpos($race, 'Ascot')) && $currMonth == 6) {
  328. $race = 'Royal Ascot';
  329. }
  330. elseif ($race == 'Market') {
  331. $race = 'Market Rasen';
  332. }
  333.  
  334. elseif ($race == 'Down') {
  335. $race = 'Down Royal';
  336. }
  337. elseif ($race == 'Ffos') {
  338. $race = 'Ffos Las';
  339. }
  340.  
  341. $hours[] = $hour;
  342. $type = substr($row[2], strpos($row[2], '-> ')+3);
  343. $types[] = substr($type, 0, strpos($type, ' '));
  344. $horse = substr($type, strpos($type, ' ')+1);
  345. $horse = htmlentities($horse, null, 'utf-8');
  346. $horse = str_replace("&nbsp;", "", $horse);
  347. $horses[] = html_entity_decode($horse);
  348. //$tipsters[] = $row[3];
  349. //$profits[] = $profit;
  350.  
  351. $odds[] = $row[3];
  352. $races[] = $race;
  353. }
  354. }
  355.  
  356. $cont++;
  357. //echo "$cont\n";
  358. }
  359.  
  360. for ($i=0; $i < count($hours); $i++) {
  361. $csv = array_fill(0, 8, '');
  362.  
  363. $csv[1] = $races[$i];
  364. $csv[2] = 'Today';
  365. $csv[3] = $hours[$i];
  366. $csv[4] = trim($horses[$i]);
  367. $csv[5] = '-';
  368. $csv[6] = $types[$i];
  369. $csv[7] = $odds[$i];
  370.  
  371. fputcsv($fileOut, $csv);
  372. }
  373. fclose($fileOut);
  374. SelectRacesAccum($horses, $hours, $odds, $types, $races);
  375. }
  376.  
  377. function SelectRacesAccum($horses, $hourss, $odds, $types, $venues){
  378. ///Select races
  379.  
  380. $optionsFile = fopen("options.csv", "r");
  381. $options = fgetcsv($optionsFile);
  382. fclose($optionsFile);
  383.  
  384. $timeOptions = explode(":", $options[2]);
  385. $hourOptions = $timeOptions[0];
  386. $minOptions = $timeOptions[1];
  387.  
  388.  
  389. $count = 0;
  390.  
  391. if ($options[3] == 'checked') {
  392. $optType = 'Win';
  393. }
  394. elseif ($options[4] == 'checked') {
  395. $optType = 'Each Way';
  396. }
  397. else{
  398. $optType = 'Both';
  399. }
  400.  
  401. $lastIndex = 0;
  402. for ($i=0; $i < count($horses); $i++) {
  403.  
  404. if ($types[$i] == 'E/w' || $types[$i] == 'E/W') {
  405. $types[$i] = 'Each Way';
  406. }
  407. $checkbox[$i] = "";
  408.  
  409. $hours1 = $hourss[$i];
  410.  
  411. $hour = explode(":", $hours1)[0];
  412. $min = substr(explode(":", $hours1)[1], 0, 2);
  413.  
  414.  
  415. if ($hour > $hourOptions || ($hour == $hourOptions && $min >= $minOptions)) {
  416.  
  417.  
  418. if ($odds[$i] >= $options[6] && $odds[$i] <= $options[13]) {
  419.  
  420. if ($types[$i] == $optType || $optType == "Both") {
  421.  
  422. if ($hour > $lastHour || ($hour == $lastHour && ($min-$lastMinute >= 20))) {
  423. if ($count < $options[7]) {
  424. $lastHour = $hour;
  425. $lastMinute = $min;
  426. $lastIndex = $i;
  427. $checkbox[$i] = "checked";
  428. $count++;
  429. }
  430. }
  431. elseif ($venues[$i] == $venues[$lastIndex]) {
  432. if ($types[$lastIndex] == 'Each Way' && $types[$i] == 'Win') {
  433. $checkbox[$i] = "checked";
  434. $checkbox[$lastIndex] = "";
  435. $lastIndex = $i;
  436. }
  437. elseif ($types[$i] == $types[$lastIndex]) {
  438. if ($odds[$i] < $odds[$lastIndex]) {
  439. $checkbox[$i] = "checked";
  440. $checkbox[$lastIndex] = "";
  441. $lastIndex = $i;
  442. }
  443. }
  444. }
  445.  
  446. }
  447.  
  448. }
  449.  
  450. }
  451.  
  452.  
  453. }
  454.  
  455. $file = fopen(getcwd().EX_PATH.'tips.csv', 'w');
  456. $tipsForBetFile = fopen(getcwd().EX_PATH.'tipsForBets.csv', 'w');
  457. $tipPos = 0;
  458.  
  459. for ($i=0; $i < count($horses); $i++) {
  460. $csv = array_fill(0, 8, '') ;
  461. $csv = [$checkbox[$i],$venues[$i],'Today',$hourss[$i],$horses[$i],'-',$types[$i],$odds[$i]];
  462. fputcsv($file, $csv);
  463.  
  464. if ($checkbox[$i] == 'checked') {
  465. $tipPos ++;
  466. array_unshift($csv, $tipPos);
  467. fputcsv($tipsForBetFile, $csv);
  468. }
  469. }
  470. fclose($file);
  471. fclose($tipsForBetFile);
  472.  
  473.  
  474. $statusFile = fopen(getcwd().'/Betting_System/betStatus.csv','w');
  475. fputcsv($statusFile, [0,0,0,0]);
  476. fclose($statusFile);
  477.  
  478.  
  479. $csv = array();
  480.  
  481. $newFile = fopen(getcwd().EX_PATH.'updateTipster.csv', 'w');
  482. $csv[0] = 'AndyHolding';
  483. date_default_timezone_set('Europe/London');
  484. $csv[1] = date('Y-m-d H:i');
  485. fputcsv($newFile, $csv);
  486. fclose($newFile);
  487. }
  488.  
  489. function InitializeStatus($nTips){
  490.  
  491. $betIds = array_fill(0, $nTips, '');
  492. $statusFile = fopen(getcwd().BT_PATH.'BTStatus.csv','w');
  493. for ($i=0; $i < count($betIds); $i++) {
  494. $csv = [];
  495. $csv[] = $betIds[$i];
  496. fputcsv($statusFile, $csv);
  497. }
  498.  
  499. }
  500. function updateTime($time){
  501.  
  502. $updateFile = getcwd().BT_PATH.'updateTime.txt';
  503. file_put_contents($updateFile, $time);
  504.  
  505. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement