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 main() { switch ($_GET["get"]) { case "stations": connectDB(); echo json_encode(getStations($_GET["lat"], $_GET["lng"], $_GET["radius"])); break; case "station": connectDB(); echo json_encode(getStation($_GET["id"])); break; case "cron": global $cronjob_key; if ($_GET["key"] == $cronjob_key) { cron(); } break; case "info": connectDB(); getInfo(true); break; default: header("Location: https://github.com/xXSparkeyy/harbour-spritradar"); } }