Add geonames.org timezone API

This commit is contained in:
2022-04-13 22:46:25 +02:00
parent 4b88759173
commit a2b80484ef
2 changed files with 19 additions and 1 deletions

View File

@@ -28,6 +28,12 @@ class Feed extends PhpObject {
'iconSet' => 'icons2' 'iconSet' => 'icons2'
); );
//Timezone
const TIMEZONE_HOOK = 'http://api.geonames.org/timezoneJSON';
const TIMEZONE_PARAM = array(
'username' => Settings::TIMEZONE_USER
);
//DB Tables //DB Tables
const SPOT_TABLE = 'spots'; const SPOT_TABLE = 'spots';
const FEED_TABLE = 'feeds'; const FEED_TABLE = 'feeds';
@@ -202,7 +208,7 @@ class Feed extends PhpObject {
'longitude' => $asMsg['longitude'], 'longitude' => $asMsg['longitude'],
'iso_time' => $asMsg['dateTime'], //ISO 8601 time (backup) 'iso_time' => $asMsg['dateTime'], //ISO 8601 time (backup)
'site_time' => date(Db::TIMESTAMP_FORMAT, $asMsg['unixTime']), //Conversion to Site Time 'site_time' => date(Db::TIMESTAMP_FORMAT, $asMsg['unixTime']), //Conversion to Site Time
'timezone' => Spot::getTimeZoneFromDate($asMsg['dateTime']), //Local Time Zone 'timezone' => $this->getTimeZone(array($asMsg['latitude'], $asMsg['longitude']), $asMsg['unixTime']),
'unix_time' => $asMsg['unixTime'], //UNIX Time (backup) 'unix_time' => $asMsg['unixTime'], //UNIX Time (backup)
'content' => $asMsg['messageContent'], 'content' => $asMsg['messageContent'],
'battery_state' => $asMsg['batteryState'] 'battery_state' => $asMsg['batteryState']
@@ -256,6 +262,17 @@ class Feed extends PhpObject {
); );
} }
private function getTimeZone($asLatLng, $iTimeStamp) {
$asParams = self::TIMEZONE_PARAM;
$asParams['lat'] = $asLatLng[0];
$asParams['lng'] = $asLatLng[1];
$sApiUrl = self::TIMEZONE_HOOK.'?'.http_build_query($asParams);
$asTimeZone = json_decode(file_get_contents($sApiUrl), true);
return $asTimeZone['timezoneId'] ?? Settings::TIMEZONE;
}
private function retrieveFeed() { private function retrieveFeed() {
$sContent = '[]'; $sContent = '[]';
if($this->sRefFeedId !='') { if($this->sRefFeedId !='') {

View File

@@ -14,5 +14,6 @@ class Settings
const MAIL_USER = ''; const MAIL_USER = '';
const MAIL_PASS = ''; const MAIL_PASS = '';
const WEATHER_TOKEN = ''; //visualcrossing.com const WEATHER_TOKEN = ''; //visualcrossing.com
const TIMEZONE_USER = ''; //geonames.org
const DEBUG = true; const DEBUG = true;
} }