Пример #1
0
 public function get_farmacienow($where)
 {
     $time = date('d/m/Y');
     exec('curl -v -c db/cookies.txt "http://www.sanita.puglia.it/gestione-farmacie-di-turno" ');
     exec('curl -v -b db/cookies.txt -L "http://www.sanita.puglia.it/web/pugliasalute/gestione-farmacie-di-turno?p_p_id=farmacie_WAR_PugliaSalutePortlet&p_p_lifecycle=2&p_p_state=normal&p_p_mode=view&p_p_resource_id=searchFdt&p_p_cacheability=cacheLevelPage&p_p_col_id=column-1&p_p_col_pos=1&p_p_col_count=2" -H "Host: www.sanita.puglia.it" -H "X-Requested-With: XMLHttpRequest" -H "User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.103 Safari/537.36" -H "Content-Type: application/json; charset=UTF-8" -H "Accept: application/json, text/javascript, */*; q=0.01" -H "Accept-Language: it-IT,it;q=0.8,en-US;q=0.6,en;q=0.4,cs;q=0.2" -H "Accept-Encoding: gzip, deflate, sdch, br" --compressed -H "Referer: http://www.sanita.puglia.it/gestione-farmacie-di-turno" -H "Connection: keep-alive" --data "{\\""siglaProvincia\\"":\\""LE\\"",\\""codComune\\"":\\""E506\\"",\\""nomeComune\\"":\\""LECCE\\"",\\""startDate\\"":\\""' . $time . '\\"",\\""endDate\\"":\\""' . $time . '\\"",\\""checkNow\\"":true,\\""turni\\"":[]}" > db/farmacienow.txt');
     $html = file_get_contents("db/farmacienow.txt");
     $parsed_json = json_decode($html, true);
     //var_dump(  $parsed_json); // debug
     $count = 0;
     $temp = "";
     function getInnerSubstring($string, $delim)
     {
         // "foo a foo" becomes: array(""," a ","")
         $string = explode($delim, $string, 3);
         // also, we only need 2 items at most
         // we check whether the 2nd is set and return it, otherwise we return an empty string
         return isset($string[1]) ? $string[1] : '';
     }
     // echo $count."<br>";
     //echo $parsed_json->{'payload'};
     //echo $time;
     $risposta = json_encode($parsed_json["payload"][0][$time]);
     //echo $risposta."</br>\n";
     $aperte = json_decode($risposta, true)[0]["tutteLeFarmacieSonoAperte"];
     if ($aperte == 1) {
         $temp .= "Tutte le farmacie sono aperte";
         $temp .= "\n--------\n";
     }
     //var_dump($parsed_json["payload"][1]);
     foreach ($parsed_json["payload"][1] as $data => $csv1) {
         $count = $count + 1;
         $temp .= "🏥  <b>" . $csv1["nomeStruttura"] . "</b>\n";
         $temp .= "📞  " . $csv1["numeroDiTelefono"] . "\n";
         $temp .= "🏳  " . $csv1["indirizzo"] . "\n";
         $coordinate = str_replace("POINT ", "", $csv1["coordinate"]);
         $coordinate = str_replace(")", ";", $coordinate);
         $coordinate = str_replace("(", ",", $coordinate);
         $coordinate = str_replace(" ", ",;", $coordinate);
         $lat = getInnerSubstring($coordinate, ";");
         $lon = getInnerSubstring($coordinate, ",");
         $temp .= "🌐  https://www.openstreetmap.org/#map=19/" . $lat . "/" . $lon;
         $temp .= "\n--------\n";
     }
     return $temp;
 }
Пример #2
0
function make_regexp($query)
{
    /*
     * De 1e stap is tellen hoeveek er haakje svoor komen
     */
    if (substr_count($query, '*') >= 1) {
        return false;
    }
    //Tel alle openingshaakjes
    $count_open = substr_count($query, '(');
    //Tel aale sluithaakjes
    $count_close = substr_count($query, ')');
    //Als er het aantal haakjes niet gelijk is sluit gelijk alles
    if ($count_close !== $count_open) {
        return false;
    }
    if ($count_open == 1) {
        if (substr($query, -1) == ')' and substr($query, 0, 1) == '(') {
            $count_open = 0;
        }
    }
    //Hier gaan we opdelen in geen haakjes of 1 paar haakjes of meerder haakjes
    //Als er geen haakjes zijn gevonden
    if ($count_open == 0) {
        //Tel nu hoe vaak het woordt AND voor komt
        $count_and = substr_count($query, 'AND');
        if ($count_and == 0) {
            //Als er geen AND in voor komt gaat er iets mis
            return single($query);
            //Als er 1x and in voor komt
        } elseif ($count_and == 1) {
            //Als er And voor kom zet dan alles keys om en een regexp
            return get_title_key($query);
            //Als er meer dan 1 AND in voor komt
        } else {
            //Er komen nu geen haakjes voor maar wel dan 1 x AND
            return no_end_more_and($query);
        }
        //Als er 1 paar haakjes voor komt
    } elseif ($count_open == 1) {
        //Tel hoe vaak komt AND voor
        $count_and = substr_count($query, 'AND');
        //Als het 1x voor komt
        if ($count_and == 1) {
            //Haal op wat voor de AND staat
            $befor = strstr($query, 'AND', true);
            if (substr_count($befor, ')')) {
                //De haakjes staan voor de AND
                return single_par_before($query);
            } else {
                //De haakjes staam ma de AND
                return single_par_after($query);
            }
            //Als het meer dan 1 x voor komt
        } else {
            //Ga kijken of de AND tussen de haakjes staat of er na komet
            $substring = getInnerSubstring($query, "AND");
            $count = substr_count($substring, ')');
            //De and staat tussen haakjes
            if ($count == 1) {
                //De haakjes staan voor de and en er staan een sand tussen
                return single_par_before_more_and($query);
                //De and komt na de haakjes
            } else {
                //De haakjes staam ma de AND
                return single_par_after($query);
            }
        }
        //Als er meer haakje svoor komen
    } else {
        //Er zijn meer haakjes
        return multi_par($query);
    }
}