mirror of
https://github.com/tuxbox-fork-migrations/recycled-ni-neutrino.git
synced 2025-08-27 15:32:52 +02:00
add find weather location by postcode
todo: add country
Origin commit data
------------------
Branch: ni/coolstream
Commit: b2b2d605dc
Author: TangoCash <eric@loxat.de>
Date: 2022-01-20 (Thu, 20 Jan 2022)
------------------
This commit was generated by Migit
This commit is contained in:
@@ -1904,6 +1904,7 @@ menu.hint_volume_size Wählen Sie die Höhe der Lautstärkeanzeige
|
|||||||
menu.hint_weather_api_key Geben Sie den OpenWeather API Schlüssel ein. Eine leere Eingabe schaltet die Wetter-Unterstützung aus
|
menu.hint_weather_api_key Geben Sie den OpenWeather API Schlüssel ein. Eine leere Eingabe schaltet die Wetter-Unterstützung aus
|
||||||
menu.hint_weather_enabled Schaltet die Wetter-Unterstützung (openweathermap.org) ein bzw. aus
|
menu.hint_weather_enabled Schaltet die Wetter-Unterstützung (openweathermap.org) ein bzw. aus
|
||||||
menu.hint_weather_location Wählen Sie eine Stadt in ihrer Nähe zur Anzeige der Wetterdaten aus
|
menu.hint_weather_location Wählen Sie eine Stadt in ihrer Nähe zur Anzeige der Wetterdaten aus
|
||||||
|
menu.hint_weather_location_postcode Geben Sie ihre Postleitzahl zur Anzeige der Wetterdaten an
|
||||||
menu.hint_webradio_setup Hier konfigurierte WebRadio-Kanäle finden Sie in der Kanalverwaltung.
|
menu.hint_webradio_setup Hier konfigurierte WebRadio-Kanäle finden Sie in der Kanalverwaltung.
|
||||||
menu.hint_webradio_xml_auto Lädt automatisch alle WebRadio-Dateien aus %s/ und %s/
|
menu.hint_webradio_xml_auto Lädt automatisch alle WebRadio-Dateien aus %s/ und %s/
|
||||||
menu.hint_webtv_setup Hier konfigurierte WebTV-Kanäle finden Sie in der Kanalverwaltung.
|
menu.hint_webtv_setup Hier konfigurierte WebTV-Kanäle finden Sie in der Kanalverwaltung.
|
||||||
@@ -3038,6 +3039,7 @@ videomenu.zappingmode_hold Standbild
|
|||||||
weather.api_key Wetter API Schlüssel (OpenWeather)
|
weather.api_key Wetter API Schlüssel (OpenWeather)
|
||||||
weather.enabled Wetter-Unterstützung
|
weather.enabled Wetter-Unterstützung
|
||||||
weather.location Wetter-Standort
|
weather.location Wetter-Standort
|
||||||
|
weather.location_postcode Wetter-Standort per Postleitzahl
|
||||||
webchannels.xml.add Hinzufügen
|
webchannels.xml.add Hinzufügen
|
||||||
webchannels.xml.del Entfernen
|
webchannels.xml.del Entfernen
|
||||||
webchannels.xml.enter Eintragen
|
webchannels.xml.enter Eintragen
|
||||||
|
@@ -1904,6 +1904,7 @@ menu.hint_volume_size Select volume indicator height
|
|||||||
menu.hint_weather_api_key Type your OpenWeather API key. An empty input disables Weather support
|
menu.hint_weather_api_key Type your OpenWeather API key. An empty input disables Weather support
|
||||||
menu.hint_weather_enabled Enable or disable Weather support (openweathermap.org)
|
menu.hint_weather_enabled Enable or disable Weather support (openweathermap.org)
|
||||||
menu.hint_weather_location Select your weather location
|
menu.hint_weather_location Select your weather location
|
||||||
|
menu.hint_weather_location_postcode Select your weather location by postcode
|
||||||
menu.hint_webradio_setup WebRadio channels configured here will be available in the standard channel lists.
|
menu.hint_webradio_setup WebRadio channels configured here will be available in the standard channel lists.
|
||||||
menu.hint_webradio_xml_auto Auto-load all existing WebRadio files from %s/ and %s/
|
menu.hint_webradio_xml_auto Auto-load all existing WebRadio files from %s/ and %s/
|
||||||
menu.hint_webtv_setup WebTV channels configured here will be available in the standard channel lists.
|
menu.hint_webtv_setup WebTV channels configured here will be available in the standard channel lists.
|
||||||
@@ -3038,6 +3039,7 @@ videomenu.zappingmode_hold Hold screen
|
|||||||
weather.api_key Weather API key (OpenWeather)
|
weather.api_key Weather API key (OpenWeather)
|
||||||
weather.enabled Weather support
|
weather.enabled Weather support
|
||||||
weather.location Weather location
|
weather.location Weather location
|
||||||
|
weather.location_postcode Weather location by postcode
|
||||||
webchannels.xml.add Add
|
webchannels.xml.add Add
|
||||||
webchannels.xml.del Remove
|
webchannels.xml.del Remove
|
||||||
webchannels.xml.enter Enter
|
webchannels.xml.enter Enter
|
||||||
|
@@ -182,6 +182,42 @@ bool CWeather::GetWeatherDetails()
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool CWeather::FindCoords(int postcode, std::string country)
|
||||||
|
{
|
||||||
|
std::string data = "http://api.openweathermap.org/geo/1.0/zip?zip=" + std::to_string(postcode) + ","+country+"&appid=" + key;
|
||||||
|
JSONCPP_STRING answer;
|
||||||
|
JSONCPP_STRING formattedErrors;
|
||||||
|
Json::CharReaderBuilder builder;
|
||||||
|
Json::CharReader *reader = builder.newCharReader();
|
||||||
|
Json::Value DataValues;
|
||||||
|
answer.clear();
|
||||||
|
|
||||||
|
if (!getUrl(data, answer))
|
||||||
|
{
|
||||||
|
delete reader;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool parsedSuccess = reader->parse(answer.c_str(), answer.c_str() + answer.size(), &DataValues, &formattedErrors);
|
||||||
|
delete reader;
|
||||||
|
|
||||||
|
if (!parsedSuccess)
|
||||||
|
{
|
||||||
|
printf("Failed to parse JSON\n");
|
||||||
|
printf("%s\n", formattedErrors.c_str());
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (DataValues["message"].asString() == "not found")
|
||||||
|
return false;
|
||||||
|
|
||||||
|
float lat = DataValues["lat"].asFloat();
|
||||||
|
float lon = DataValues["lon"].asFloat();
|
||||||
|
g_settings.weather_city = DataValues["name"].asString();
|
||||||
|
g_settings.weather_location = std::to_string(lat) + "," + std::to_string(lon);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
void CWeather::show(int x, int y)
|
void CWeather::show(int x, int y)
|
||||||
{
|
{
|
||||||
checkUpdate();
|
checkUpdate();
|
||||||
|
@@ -91,6 +91,7 @@ class CWeather
|
|||||||
~CWeather();
|
~CWeather();
|
||||||
bool checkUpdate(bool forceUpdate = false);
|
bool checkUpdate(bool forceUpdate = false);
|
||||||
void setCoords(std::string new_coords, std::string new_city = "Unknown");
|
void setCoords(std::string new_coords, std::string new_city = "Unknown");
|
||||||
|
bool FindCoords(int postcode, std::string country = "DE");
|
||||||
|
|
||||||
// globals
|
// globals
|
||||||
std::string getCity()
|
std::string getCity()
|
||||||
|
@@ -63,6 +63,10 @@ int CWeatherSetup::exec(CMenuTarget *parent, const std::string &actionKey)
|
|||||||
{
|
{
|
||||||
return showSelectWeatherLocation();
|
return showSelectWeatherLocation();
|
||||||
}
|
}
|
||||||
|
else if (actionKey == "find_location")
|
||||||
|
{
|
||||||
|
return findLocation();
|
||||||
|
}
|
||||||
|
|
||||||
res = showWeatherSetup();
|
res = showWeatherSetup();
|
||||||
|
|
||||||
@@ -90,6 +94,10 @@ int CWeatherSetup::showWeatherSetup()
|
|||||||
mf_wl->setHint(NEUTRINO_ICON_HINT_SETTINGS, LOCALE_MENU_HINT_WEATHER_LOCATION);
|
mf_wl->setHint(NEUTRINO_ICON_HINT_SETTINGS, LOCALE_MENU_HINT_WEATHER_LOCATION);
|
||||||
ms_oservices->addItem(mf_wl);
|
ms_oservices->addItem(mf_wl);
|
||||||
|
|
||||||
|
CMenuForwarder *mf_zip = new CMenuForwarder(LOCALE_WEATHER_LOCATION_POSTCODE, g_settings.weather_enabled, NULL, this, "find_location");
|
||||||
|
mf_zip->setHint(NEUTRINO_ICON_HINT_SETTINGS, LOCALE_MENU_HINT_WEATHER_LOCATION_POSTCODE);
|
||||||
|
ms_oservices->addItem(mf_zip);
|
||||||
|
|
||||||
int res = ms_oservices->exec(NULL, "");
|
int res = ms_oservices->exec(NULL, "");
|
||||||
selected = ms_oservices->getSelected();
|
selected = ms_oservices->getSelected();
|
||||||
delete ms_oservices;
|
delete ms_oservices;
|
||||||
@@ -146,6 +154,22 @@ int CWeatherSetup::showSelectWeatherLocation()
|
|||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int CWeatherSetup::findLocation()
|
||||||
|
{
|
||||||
|
int ret = menu_return::RETURN_REPAINT;
|
||||||
|
int postcode = 10178;
|
||||||
|
CIntInput zipcode(LOCALE_WEATHER_LOCATION_POSTCODE, &postcode, (unsigned int)5);
|
||||||
|
ret = zipcode.exec(NULL, "");
|
||||||
|
zipcode.hide();
|
||||||
|
|
||||||
|
if (CWeather::getInstance()->FindCoords(postcode))
|
||||||
|
{
|
||||||
|
CWeather::getInstance()->setCoords(g_settings.weather_location, g_settings.weather_city);
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
bool CWeatherSetup::changeNotify(const neutrino_locale_t OptionName, void */*data*/)
|
bool CWeatherSetup::changeNotify(const neutrino_locale_t OptionName, void */*data*/)
|
||||||
{
|
{
|
||||||
int ret = menu_return::RETURN_NONE;
|
int ret = menu_return::RETURN_NONE;
|
||||||
|
@@ -44,6 +44,7 @@ class CWeatherSetup : public CMenuTarget, CChangeObserver
|
|||||||
|
|
||||||
int showWeatherSetup();
|
int showWeatherSetup();
|
||||||
int showSelectWeatherLocation();
|
int showSelectWeatherLocation();
|
||||||
|
int findLocation();
|
||||||
void loadLocations(std::string filename);
|
void loadLocations(std::string filename);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
@@ -1931,6 +1931,7 @@ typedef enum
|
|||||||
LOCALE_MENU_HINT_WEATHER_API_KEY,
|
LOCALE_MENU_HINT_WEATHER_API_KEY,
|
||||||
LOCALE_MENU_HINT_WEATHER_ENABLED,
|
LOCALE_MENU_HINT_WEATHER_ENABLED,
|
||||||
LOCALE_MENU_HINT_WEATHER_LOCATION,
|
LOCALE_MENU_HINT_WEATHER_LOCATION,
|
||||||
|
LOCALE_MENU_HINT_WEATHER_LOCATION_POSTCODE,
|
||||||
LOCALE_MENU_HINT_WEBRADIO_SETUP,
|
LOCALE_MENU_HINT_WEBRADIO_SETUP,
|
||||||
LOCALE_MENU_HINT_WEBRADIO_XML_AUTO,
|
LOCALE_MENU_HINT_WEBRADIO_XML_AUTO,
|
||||||
LOCALE_MENU_HINT_WEBTV_SETUP,
|
LOCALE_MENU_HINT_WEBTV_SETUP,
|
||||||
@@ -3065,6 +3066,7 @@ typedef enum
|
|||||||
LOCALE_WEATHER_API_KEY,
|
LOCALE_WEATHER_API_KEY,
|
||||||
LOCALE_WEATHER_ENABLED,
|
LOCALE_WEATHER_ENABLED,
|
||||||
LOCALE_WEATHER_LOCATION,
|
LOCALE_WEATHER_LOCATION,
|
||||||
|
LOCALE_WEATHER_LOCATION_POSTCODE,
|
||||||
LOCALE_WEBCHANNELS_XML_ADD,
|
LOCALE_WEBCHANNELS_XML_ADD,
|
||||||
LOCALE_WEBCHANNELS_XML_DEL,
|
LOCALE_WEBCHANNELS_XML_DEL,
|
||||||
LOCALE_WEBCHANNELS_XML_ENTER,
|
LOCALE_WEBCHANNELS_XML_ENTER,
|
||||||
|
@@ -1931,6 +1931,7 @@ const char * locale_real_names[] =
|
|||||||
"menu.hint_weather_api_key",
|
"menu.hint_weather_api_key",
|
||||||
"menu.hint_weather_enabled",
|
"menu.hint_weather_enabled",
|
||||||
"menu.hint_weather_location",
|
"menu.hint_weather_location",
|
||||||
|
"menu.hint_weather_location_postcode",
|
||||||
"menu.hint_webradio_setup",
|
"menu.hint_webradio_setup",
|
||||||
"menu.hint_webradio_xml_auto",
|
"menu.hint_webradio_xml_auto",
|
||||||
"menu.hint_webtv_setup",
|
"menu.hint_webtv_setup",
|
||||||
@@ -3065,6 +3066,7 @@ const char * locale_real_names[] =
|
|||||||
"weather.api_key",
|
"weather.api_key",
|
||||||
"weather.enabled",
|
"weather.enabled",
|
||||||
"weather.location",
|
"weather.location",
|
||||||
|
"weather.location_postcode",
|
||||||
"webchannels.xml.add",
|
"webchannels.xml.add",
|
||||||
"webchannels.xml.del",
|
"webchannels.xml.del",
|
||||||
"webchannels.xml.enter",
|
"webchannels.xml.enter",
|
||||||
|
Reference in New Issue
Block a user