Add OpenWeatherMap provider

master
Skylar Ittner 1 year ago
parent a8b3ba10c1
commit b11ec93c83

@ -0,0 +1,76 @@
<?php
/*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
class Weather_OWM extends Weather {
public function loadForecast() {
global $SETTINGS;
$apikey = $SETTINGS['apikeys']['openweathermap.org'];
$url = "https://api.openweathermap.org/data/3.0/onecall";
$json = ApiFetcher::get($url, ["lat" => $this->lat, "lon" => $this->lng, "exclude" => "minutely,hourly", "units" => "ca", "lang" => $SETTINGS['language']], ["appid" => $apikey]);
$resp = json_decode($json);
$currently = new Conditions();
$currently->lat = $this->lat;
$currently->lng = $this->lng;
$currently->time = $resp->current->dt;
$currently->summary = $resp->current->weather->description;
$currently->setDayorNight();
$currently->temperature = $resp->current->temp;
$currently->tempFeels = $resp->current->feels_like;
//$currently->precipProbability = $resp->current->precipProbability; // FIX
//$currently->ozone = $resp->current->ozone; // FIX
$currently->dewpoint = $resp->current->dew_point;
$currently->cloudCover = $resp->current->clouds;
$currently->humidity = $resp->current->humidity;
$currently->visibility = $resp->current->visibility;
$currently->uvindex = $resp->current->uvi;
$currently->windSpeed = $resp->current->wind_speed;
$currently->windGust = $resp->current->wind_gust;
$currently->windBearing = $resp->current->wind_deg;
$this->setCurrently($currently);
foreach ($resp->daily as $day) {
$daily = new Conditions();
$daily->lat = $this->lat;
$daily->lng = $this->lng;
$daily->time = $day->dt;
$daily->summary = $day->weather->description;
$daily->setDayorNight();
$daily->disablenight = true;
$daily->tempHigh = $day->temp->day;
$daily->tempLow = $day->temp->night;
//$daily->precipProbability = $day->precipProbability;
//$daily->ozone = $day->ozone;
$daily->dewpoint = $day->dew_point;
$daily->cloudCover = $day->clouds;
$daily->humidity = $day->humidity;
$daily->visibility = $day->visibility;
$daily->uvindex = $day->uvi;
$daily->windSpeed = $day->wind_speed;
$daily->windGust = $day->wind_gust;
$daily->windBearing = $day->wind_deg;
$this->conditions[] = $daily;
}
}
}

@ -40,6 +40,7 @@ $SETTINGS = [
"apikeys" => [
"newsapi.org" => "",
"darksky.net" => "",
"openweathermap.org" => "",
"twitter.com" => [
"consumer_key" => "",
"consumer_secret" => ""
@ -51,7 +52,7 @@ $SETTINGS = [
"NewsAPI",
"Reddit"
],
"weather" => "DarkSky"
"weather" => "OWM"
],
// Location of MaxMind GeoIP database
// Required attribution: This product includes GeoLite2 data created by

Loading…
Cancel
Save