Advertisement
Guest User

Untitled

a guest
Apr 22nd, 2019
181
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.44 KB | None | 0 0
  1. public function updateTerminal2() {
  2. $html = file_get_contents('https://www.manila-airport.net/naia-arrivals-terminal-2'); //get the html returned from the following url
  3. $tableData = array();
  4. $pokemon_doc = new \DOMDocument();
  5. libxml_use_internal_errors(TRUE); //disable libxml errors
  6.  
  7.  
  8. if (!empty($html)) { //if any html is actually returned
  9. $pokemon_doc->loadHTML($html);
  10. libxml_clear_errors(); //remove errors for yucky html
  11. $pokemon_xpath = new \DOMXPath($pokemon_doc);
  12.  
  13. $pokemon_row = $pokemon_xpath->query('//div[contains(@id,"flight_detail")] and @class!="adsense"');
  14.  
  15.  
  16. $tempData = array();
  17. $data = array();
  18. $processData = array();
  19. $count = 0;
  20. $toPushItem = new \StdClass;
  21. foreach ($pokemon_row as $key => $row) {
  22.  
  23. $data[] = $row->nodeValue;
  24. // unset($data[0]);
  25. // unset($data[1]);
  26. // unset($data[2]);
  27. // unset($data[3]);
  28. // unset($data[4]);
  29.  
  30. }
  31.  
  32.  
  33. end($data);
  34. $key = key($data);
  35. for ($j = 2; $j < $key; $j +=3) {
  36. $count++;
  37. $tempDatas[] = $data[$j];
  38.  
  39.  
  40. for ($i = 2; $i != $key; $i++) {
  41.  
  42. //$tempDatas[] = $data[$i];
  43.  
  44. }
  45.  
  46.  
  47.  
  48. // if ($count == 2) {
  49. //
  50. // $toPushItem = $tempData[0];
  51. //// $toPushItem->Carrier = $tempData[1];
  52. //// $toPushItem->Destination = $tempData[2];
  53. //// $toPushItem->Departure = $tempData[3];
  54. //// $toPushItem->Status = $tempData[4];
  55. // $processData[] = $toPushItem;
  56. //
  57. // $count = 0;
  58. // $tempData = array();
  59. // $toPushItem = new \StdClass;
  60. // }
  61. }
  62.  
  63.  
  64. foreach ($tempDatas as $key => $data2){
  65.  
  66.  
  67. // if ($key == 25) continue;
  68.  
  69. $buffer = str_replace(array("\n", ), ',', $data2);
  70. $buffer = str_replace(array(",,,",",," ), ',', $buffer);
  71. $string = trim($buffer,",");
  72.  
  73. $x = preg_replace('/\s*,\s*/', ',', $string);
  74.  
  75. $myArray[] = explode(',', $x);
  76.  
  77.  
  78.  
  79. // $buffer = str_replace(array("\n", ), ',', $data2);
  80. // $buffer = str_replace(array(",,,",",," ), ',', $buffer);
  81. // $string = trim($buffer,",");
  82. //
  83. // $x = preg_replace('/\s*,\s*/', ',', $string);
  84. //
  85. // $myArray[] = explode(',', $x);
  86. }
  87.  
  88.  
  89. // print_r($myArray);exit;
  90. //
  91. $json = json_encode($myArray);
  92. $array = json_decode($json, true);
  93. //
  94. print_r($array);exit;
  95.  
  96.  
  97.  
  98. $mostRecent = 0;
  99. foreach ($array as $Date) {
  100.  
  101. // $name = str_replace('/','_',$Date['DrawDate']);
  102. // print_r($name);exit;
  103. //
  104. // $name = str_replace('/','_',$Date["3"]);
  105. // print_r($name);exit;
  106.  
  107.  
  108. $originalDate = $Date["3"];
  109. $newDate = date("Y-m-d", strtotime($originalDate));
  110. $ByDate[$newDate][] = $Date;
  111.  
  112. $lastDate[] = $newDate;
  113.  
  114. $mostRecent = array('lastDate' => max(array_unique($lastDate)));
  115.  
  116.  
  117. // $ByDate[$name][] = $Date;
  118.  
  119.  
  120. }
  121. $day = $mostRecent["lastDate"];
  122. $lastArray = [];
  123.  
  124.  
  125. foreach ($ByDate as $final => $value) {
  126. $lastArray[$final] = $value;
  127. }
  128.  
  129. $data = json_encode($lastArray[$day]);
  130.  
  131. $data2 = json_encode($mostRecent);
  132.  
  133. // print_r(max($mostRecent));exit;
  134. $url = "https://pcso-lotto-ph.firebaseio.com/results2/t3/$day.json";
  135. $ch = curl_init($url);
  136. curl_setopt($ch, CURLOPT_HTTPHEADER, array(
  137. 'Content-Type: application/json',
  138. 'Content-Length: ' . strlen($data))
  139. );
  140. curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT");
  141. curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
  142. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  143. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
  144. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
  145.  
  146. $jsonResponse = curl_exec($ch);
  147. if (curl_errno($ch)) {
  148. echo 'Curl error: ' . curl_error($ch);
  149. }
  150.  
  151. curl_close($ch);
  152.  
  153. $url2 = "https://pcso-lotto-ph.firebaseio.com/last2.json";
  154. $ch2 = curl_init($url2);
  155. curl_setopt($ch2, CURLOPT_HTTPHEADER, array(
  156. 'Content-Type: application/json',
  157. 'Content-Length: ' . strlen($data2))
  158. );
  159. curl_setopt($ch2, CURLOPT_CUSTOMREQUEST, "PUT");
  160. curl_setopt($ch2, CURLOPT_POSTFIELDS, $data2);
  161. curl_setopt($ch2, CURLOPT_RETURNTRANSFER, true);
  162. curl_setopt($ch2, CURLOPT_SSL_VERIFYHOST, 0);
  163. curl_setopt($ch2, CURLOPT_SSL_VERIFYPEER, 0);
  164.  
  165. $jsonResponse2 = curl_exec($ch2);
  166. if (curl_errno($ch2)) {
  167. echo 'Curl error: ' . curl_error($ch2);
  168. }
  169.  
  170. curl_close($ch2);
  171.  
  172. }
  173. } //END TERMINAL 2
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement