function getData($l_stations) { $l_data = array(array(), array(), array(), array()); $nb = 0; $localtime = date('H'); $stime = $localtime - 1; if ($stime == -1) { $stime = 23; } echo "stime = {$stime}<br>"; $stime = $stime . "00"; if (strlen($stime) == 3) { $stime = "0" . $stime; } $dbtime = $localtime . ":00"; $sdate1 = date("Y/m/d"); global $day; $day = date("w"); if ($localtime == "00") { $parti = explode("/", $sdate1); $sdate = giorno_prima($parti[2], $parti[1], $parti[0]); if ($day != 0) { $day--; } else { $day = 6; } } else { $sdate = date('mdy'); } for ($i = 0; $i < count($l_stations); $i++) { $data = openUrl($l_stations[$i], $sdate, $stime); $xml = simplexml_load_string($data); foreach ($xml->arrivals->arrival as $dep) { $dbdate = date("Y-m-d H:i:s", (int) $dep->time); $delay = $dep['delay']; $vehicle = str_replace("BE.NMBS.", "", $dep->vehicle); //if ((substr($dbdate,-8,2))== substr($stime,0,2)) $con =1; else $con =0; //echo substr($dbdate,-8,2)." - ".substr($stime,0,2)." $con <br>"; if (substr($dbdate, -8, 2) == substr($stime, 0, 2)) { $nb++; echo substr($dbdate, -8, 2) . "==" . substr($stime, 0, 2); array_push($l_data[0], $dbdate); array_push($l_data[1], $l_stations[$i]); array_push($l_data[2], $delay); array_push($l_data[3], $vehicle); echo "{$nb}-ARRIVAL" . $dbdate; echo " "; echo $l_stations[$i]; echo " "; echo $delay; echo " "; echo $vehicle; echo "<br>"; } } foreach ($xml->departures->departure as $dep) { $dbdate = date("Y-m-d H:i:s", (int) $dep->time); $delay = $dep['delay']; $vehicle = str_replace("BE.NMBS.", "", $dep->vehicle); if (substr($dbdate, -8, 2) == substr($stime, 0, 2)) { echo substr($dbdate, -8, 2) . "==" . substr($stime, 0, 2); $nb++; array_push($l_data[0], $dbdate); array_push($l_data[1], $l_stations[$i]); array_push($l_data[2], $delay); array_push($l_data[3], $vehicle); echo "{$nb}-DEPARTURE" . $dbdate; echo " "; echo $l_stations[$i]; echo " "; echo $delay; echo " "; echo $vehicle; echo "<br>"; } } } pdidb($l_data, $nb); }
function getData($l_stations) { //structure $l_data = array(array(), array(), array(), array(), array(), array(), array(), array(), array(), array(), array()); $nb_res = 0; $nb_commit = 0; $td = array(); //prepare time for url call -2H actual time $localtime = date('H'); $stime = $localtime - 2; if ($stime == -1) { $stime = 23; } if ($stime == -2) { $stime = 22; } if ($stime < 10) { $stime = "0" . $stime . "10"; } else { $stime = $stime . "10"; } //prepare date for url call $sdate = date("Y/m/d"); if ($localtime == "00") { $parti = explode("/", $sdate); $sdate = giorno_prima($parti[2], $parti[1], $parti[0]); } $dbdate = date('Y-m-d'); //make the url call for datas for ($i = 0; $i < count($l_stations); $i++) { //set_time_limit (5); echo "{$i}/" . count($l_stations) . " - "; $data = openUrl($l_stations[$i], $sdate, $stime); //echo "getstazione:$stazione<br><br>"; if (strlen($data) > 100) { $data2 = search($data, "/thead", "<footer"); //isolate the block of info $stazione = getStation($data); //echo $data2; $data2 = str_replace('<tr class="wtt call_public">', "", $data2); $data2 = str_replace('<tr class="wtt nonpassenger pass">', "", $data2); //RINFORZARE IL PARSING QUALCHE NUOVA CLASS METTE IN CRISI $data2 = str_replace('<span>', "", $data2); $data2 = str_replace('</span>', "", $data2); $tr = explode("</tr>", $data2); $nb_res = count($tr) - 1; $nb_commit = $nb_commit + $nb_res; //count the sum of lines for all calls echo "NUMERO RIGHE =" . $nb_commit . "<br>"; for ($k = 0; $k < count($tr); $k++) { $td[$k] = explode("</td>", $tr[$k]); } for ($j = 0; $j < count($tr) - 1; $j++) { //array_pop($td[$j]); //for ($k = 0; $k < count($td[$j]); $k++) //produce rubbish at end for ($k = 1; $k < 10; $k++) { $val = strip_tags($td[$j][$k]); array_push($l_data[$k], $val); //echo $val."|"; } //echo "<br>"; array_push($l_data[10], $stazione); array_push($l_data[0], $dbdate); } echo "<br>"; } } no_none($l_data, $nb_commit); pdidb($l_data, $nb_commit, $stime); }
function getData($l_stations) { $nb_t = 0; global $train_id; $nb_res = 0; $ts = 0; $l_data = array(array(), array(), array(), array(), array(), array()); for ($i = 0; $i < count($l_stations); $i++) { echo "{$i} "; $data = openUrl($l_stations[$i]); $obj = json_decode($data, true); $nb_res = count($obj); if ($nb_res != 0) { if ($obj[$nb_res - 1]["fermata"]["programmata"] !== null) { if (verifTimeStamp($obj[$nb_res - 1]["fermata"]["programmata"]) == 1) { for ($j = 0; $j < $nb_res; $j++) { if ($obj[$j]["fermata"]["programmata"] !== null and $obj[$j]["fermata"]["effettiva"] !== null) { $ts = $obj[$j]["fermata"]["effettiva"]; $ts_pro = $obj[$j]["fermata"]["programmata"]; $nb_t++; array_push($l_data[0], $obj[0]["stazione"]); array_push($l_data[1], $obj[$j]["stazione"]); array_push($l_data[2], timeStampToDate($ts_pro)); array_push($l_data[3], timeStampToDelay($ts_pro, $ts)); array_push($l_data[4], $train_id[$i]); array_push($l_data[5], $obj[count($obj) - 1]["stazione"]); $x = count($l_data[0]) - 1; echo "<span style='color:{$colore};font-family:arial'>"; echo "{$nb_t} - "; echo $l_data[0][$x]; echo " "; echo $l_data[1][$x]; echo " "; echo $l_data[2][$x]; echo " "; echo $l_data[3][$x]; echo " "; echo $l_data[4][$x]; echo " "; echo $l_data[5][$x]; echo "<br>"; echo "</span>"; } } } } } echo "<br><br>"; } pdidb($l_data, $nb_t); }