mirror of
https://github.com/tuxbox-fork-migrations/recycled-ni-neutrino.git
synced 2025-09-02 18:31:12 +02:00
add find weather location by postcode
todo: add country
Origin commit data
------------------
Commit: b2b2d605dc
Author: TangoCash <eric@loxat.de>
Date: 2022-01-20 (Thu, 20 Jan 2022)
This commit is contained in:
@@ -182,6 +182,42 @@ bool CWeather::GetWeatherDetails()
|
||||
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)
|
||||
{
|
||||
checkUpdate();
|
||||
|
Reference in New Issue
Block a user