LibreY

- privacy respecting meta search engine
git clone git://git.acid.vegas/LibreY.git
Log | Files | Refs | Archive | README | LICENSE

weather.php (978B)

      1 <?php
      2     class WeatherRequest extends EngineRequest {
      3         public function get_request_url () {
      4             return "https://wttr.in/@" . $_SERVER["REMOTE_ADDR"] . "?format=j1";
      5         }
      6         
      7         public function parse_results($response) {
      8             $json_response = json_decode($response, true);
      9 
     10             if (!$json_response)
     11                 return array();
     12 
     13             $current_weather = $json_response["current_condition"][0];
     14 
     15             $temp_c = $current_weather["temp_C"];
     16             $temp_f = $current_weather["temp_F"];
     17             $description = $current_weather["weatherDesc"][0]["value"];
     18 
     19             $formatted_response = "$description - $temp_c °C | $temp_f °F";
     20 
     21             $source = "https://wttr.in";
     22             return array(
     23                 "special_response" => array(
     24                     "response" => htmlspecialchars($formatted_response),
     25                     "source" => $source
     26                 )
     27             );
     28         }
     29     }
     30 ?>