From c5c968cb6548811a4b7cd06362ca65a938d157fa Mon Sep 17 00:00:00 2001 From: TangoCash Date: Thu, 20 Jan 2022 21:24:37 +0100 Subject: [PATCH] fix postcode with leading zeros Origin commit data ------------------ Commit: https://github.com/neutrino-images/ni-neutrino/commit/eef63535ae3e00fa00846c540076b80701ff1c50 Author: TangoCash Date: 2022-01-20 (Thu, 20 Jan 2022) --- src/gui/weather.cpp | 7 +++++-- src/gui/weather.h | 2 +- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/gui/weather.cpp b/src/gui/weather.cpp index bd93a617f..232237384 100644 --- a/src/gui/weather.cpp +++ b/src/gui/weather.cpp @@ -182,9 +182,12 @@ bool CWeather::GetWeatherDetails() return false; } -bool CWeather::FindCoords(int postcode, std::string country) +bool CWeather::FindCoords(int postcode, std::string country, int pc_len) { - std::string data = "http://api.openweathermap.org/geo/1.0/zip?zip=" + std::to_string(postcode) + ","+country+"&appid=" + key; + std::string pcode = std::to_string(postcode); + unsigned int number_of_zeros = pc_len - pcode.length(); + pcode.insert(0, number_of_zeros, '0'); + std::string data = "http://api.openweathermap.org/geo/1.0/zip?zip=" + pcode + "," + country + "&appid=" + key; JSONCPP_STRING answer; JSONCPP_STRING formattedErrors; Json::CharReaderBuilder builder; diff --git a/src/gui/weather.h b/src/gui/weather.h index c060fb54e..b3d9606fc 100644 --- a/src/gui/weather.h +++ b/src/gui/weather.h @@ -91,7 +91,7 @@ class CWeather ~CWeather(); bool checkUpdate(bool forceUpdate = false); void setCoords(std::string new_coords, std::string new_city = "Unknown"); - bool FindCoords(int postcode, std::string country = "DE"); + bool FindCoords(int postcode, std::string country = "DE", int pc_len = 5); // globals std::string getCity()