librex/engines/special/weather.php

32 lines
1 KiB
PHP
Raw Normal View History

<?php
2023-08-21 11:29:50 -04:00
class WeatherRequest extends EngineRequest {
public function get_request_url () {
return "https://wttr.in/@" . $_SERVER["REMOTE_ADDR"] . "?format=j1";
}
public function get_results() {
$response = curl_multi_getcontent($this->ch);
$json_response = json_decode($response, true);
2023-08-21 11:29:50 -04:00
if (!$json_response)
return array();
2023-08-21 11:29:50 -04:00
$current_weather = $json_response["current_condition"][0];
2023-08-21 11:29:50 -04:00
$temp_c = $current_weather["temp_C"];
$temp_f = $current_weather["temp_F"];
$description = $current_weather["weatherDesc"][0]["value"];
2023-08-21 11:29:50 -04:00
$formatted_response = "$description - $temp_c °C | $temp_f °F";
2023-08-21 11:29:50 -04:00
$source = "https://wttr.in";
return array(
"special_response" => array(
"response" => htmlspecialchars($formatted_response),
"source" => $source
)
);
}
}
?>