diff options
| author | George Hazan <george.hazan@gmail.com> | 2025-01-26 17:13:38 +0300 |
|---|---|---|
| committer | George Hazan <george.hazan@gmail.com> | 2025-01-26 17:13:38 +0300 |
| commit | 6c1144dab5f721108a099cc7e36b23813c3cefc1 (patch) | |
| tree | b53470770e67730ced5a18ba54136a51db8396bb /protocols/Weather/src | |
| parent | 049450602d7d1b8f3ae655d08b49f8a45d6235ba (diff) | |
fixes #1508 (Port Weather from .ini to API)
Diffstat (limited to 'protocols/Weather/src')
| -rw-r--r-- | protocols/Weather/src/proto.h | 25 | ||||
| -rw-r--r-- | protocols/Weather/src/stdafx.h | 20 | ||||
| -rw-r--r-- | protocols/Weather/src/weather_conv.cpp | 16 | ||||
| -rw-r--r-- | protocols/Weather/src/weather_data.cpp | 240 | ||||
| -rw-r--r-- | protocols/Weather/src/weather_update.cpp | 104 |
5 files changed, 177 insertions, 228 deletions
diff --git a/protocols/Weather/src/proto.h b/protocols/Weather/src/proto.h index d78ba9e4be..5b3abb45f8 100644 --- a/protocols/Weather/src/proto.h +++ b/protocols/Weather/src/proto.h @@ -1,5 +1,17 @@ #pragma once +struct WIDATAITEM +{ + WIDATAITEM(const wchar_t *_1, const wchar_t *_2, const CMStringW &_3) : + Name(_1), + Unit(_2), + Value(_3) + {} + + const wchar_t *Name, *Unit; + CMStringW Value; +}; + struct WEATHERINFO { MCONTACT hContact; @@ -131,16 +143,15 @@ class CWeatherProto : public PROTO<CWeatherProto> // conversions void numToStr(double num, wchar_t *str, size_t strSize); - void GetTemp(wchar_t *tempchar, wchar_t *unit, wchar_t *str); - void GetSpeed(wchar_t *tempchar, wchar_t *unit, wchar_t *str); - void GetPressure(wchar_t *tempchar, wchar_t *unit, wchar_t *str); - void GetDist(wchar_t *tempchar, wchar_t *unit, wchar_t *str); - void GetElev(wchar_t *tempchar, wchar_t *unit, wchar_t *str); + void GetTemp(const wchar_t *tempchar, const wchar_t *unit, wchar_t *str); + void GetSpeed(const wchar_t *tempchar, const wchar_t *unit, wchar_t *str); + void GetPressure(const wchar_t *tempchar, const wchar_t *unit, wchar_t *str); + void GetDist(const wchar_t *tempchar, const wchar_t *unit, wchar_t *str); + void GetElev(const wchar_t *tempchar, const wchar_t *unit, wchar_t *str); // data - void ConvertDataValue(struct WIDATAITEM *UpdateData, wchar_t *Data); + void ConvertDataValue(WIDATAITEM *UpdateData); void EraseAllInfo(void); - void GetDataValue(WIDATAITEM *UpdateData, wchar_t *Data, wchar_t **szData); void GetStationID(MCONTACT hContact, wchar_t *id, int idlen); WEATHERINFO LoadWeatherInfo(MCONTACT hContact); diff --git a/protocols/Weather/src/stdafx.h b/protocols/Weather/src/stdafx.h index 098b92f7f8..8ad0babd09 100644 --- a/protocols/Weather/src/stdafx.h +++ b/protocols/Weather/src/stdafx.h @@ -118,24 +118,6 @@ enum EWeatherCondition #define WM_UPDATEDATA (WM_USER + 2687)
/////////////////////////////////////////////////////////////////////////////////////////
-// DATA FORMAT STRUCT
-
-#define WID_NORMAL 0
-#define WID_SET 1
-#define WID_BREAK 2
-
-struct WIDATAITEM
-{
- wchar_t *Name;
- wchar_t *Start;
- wchar_t *End;
- wchar_t *Unit;
- char *Url;
- wchar_t *Break;
- int Type;
-};
-
-/////////////////////////////////////////////////////////////////////////////////////////
// GLOBAL VARIABLES
extern HWND hPopupWindow;
@@ -166,8 +148,6 @@ wchar_t *GetError(int code); /////////////////////////////////////////////////////////////////////////////////////////
// functions in weather_data.c
-int DBGetData(MCONTACT hContact, char *setting, DBVARIANT *dbv);
-
void DBDataManage(MCONTACT hContact, uint16_t Mode, WPARAM wParam, LPARAM lParam);
/////////////////////////////////////////////////////////////////////////////////////////
diff --git a/protocols/Weather/src/weather_conv.cpp b/protocols/Weather/src/weather_conv.cpp index 7bcd8e4030..d9f35264b0 100644 --- a/protocols/Weather/src/weather_conv.cpp +++ b/protocols/Weather/src/weather_conv.cpp @@ -30,7 +30,7 @@ string conversions, display text parsing, etc // s = the string to be determined // return value = true if the string is a number, false if it isn't -BOOL is_number(wchar_t *s) +BOOL is_number(const wchar_t *s) { BOOL tag = FALSE; // looking character by character @@ -75,16 +75,12 @@ void CWeatherProto::numToStr(double num, wchar_t *str, size_t strSize) // unit = the unit for temperature // return value = the converted temperature with degree sign and unit; if fails, return N/A -void CWeatherProto::GetTemp(wchar_t *tempchar, wchar_t *unit, wchar_t *str) +void CWeatherProto::GetTemp(const wchar_t *tempchar, const wchar_t *unit, wchar_t *str) { // unit can be C, F double temp; wchar_t tstr[20]; - TrimString(tempchar); - if (tempchar[0] == '-' && tempchar[1] == ' ') - memmove(&tempchar[1], &tempchar[2], sizeof(wchar_t) * (mir_wstrlen(&tempchar[2]) + 1)); - // quit if the value obtained is N/A or not a number if (!mir_wstrcmp(tempchar, NODATA) || !mir_wstrcmp(tempchar, L"N/A")) { mir_wstrcpy(str, tempchar); @@ -129,7 +125,7 @@ void CWeatherProto::GetTemp(wchar_t *tempchar, wchar_t *unit, wchar_t *str) // unit = the unit for pressure // return value = the converted pressure with unit; if fail, return the original string -void CWeatherProto::GetPressure(wchar_t *tempchar, wchar_t *unit, wchar_t *str) +void CWeatherProto::GetPressure(const wchar_t *tempchar, const wchar_t *unit, wchar_t *str) { // unit can be kPa, hPa, mb, in, mm, torr double tempunit = 0, output; @@ -188,7 +184,7 @@ void CWeatherProto::GetPressure(wchar_t *tempchar, wchar_t *unit, wchar_t *str) // unit = the unit for speed // return value = the converted speed with unit; if fail, return _T("" -void CWeatherProto::GetSpeed(wchar_t *tempchar, wchar_t *unit, wchar_t *str) +void CWeatherProto::GetSpeed(const wchar_t *tempchar, const wchar_t *unit, wchar_t *str) { // unit can be km/h, mph, m/s, knots double tempunit; @@ -239,7 +235,7 @@ void CWeatherProto::GetSpeed(wchar_t *tempchar, wchar_t *unit, wchar_t *str) // unit = the unit for distance // return value = the converted distance with unit; if fail, return original string -void CWeatherProto::GetDist(wchar_t *tempchar, wchar_t *unit, wchar_t *str) +void CWeatherProto::GetDist(const wchar_t *tempchar, const wchar_t *unit, wchar_t *str) { // unit can be km, miles double tempunit = 0, output; @@ -281,7 +277,7 @@ void CWeatherProto::GetDist(wchar_t *tempchar, wchar_t *unit, wchar_t *str) // unit = the unit for elevation // return value = the converted elevation with unit; if fail, return original string -void CWeatherProto::GetElev(wchar_t *tempchar, wchar_t *unit, wchar_t *str) +void CWeatherProto::GetElev(const wchar_t *tempchar, const wchar_t *unit, wchar_t *str) { // unit can be ft, m double tempunit = 0, output; diff --git a/protocols/Weather/src/weather_data.cpp b/protocols/Weather/src/weather_data.cpp index ce26c27475..0db004f987 100644 --- a/protocols/Weather/src/weather_data.cpp +++ b/protocols/Weather/src/weather_data.cpp @@ -85,25 +85,6 @@ WEATHERINFO CWeatherProto::LoadWeatherInfo(MCONTACT hContact) } ///////////////////////////////////////////////////////////////////////////////////////// -// getting weather setting from database -// return 0 on success - -int DBGetData(MCONTACT hContact, char *setting, DBVARIANT *dbv) -{ - if (db_get_ws(hContact, WEATHERCONDITION, setting, dbv)) { - size_t len = mir_strlen(setting) + 1; - char *set = (char*)alloca(len + 1); - *set = '#'; - memcpy(set + 1, setting, len); - - if (db_get_ws(hContact, WEATHERCONDITION, set, dbv)) - return 1; - } - return 0; -} - - -///////////////////////////////////////////////////////////////////////////////////////// // erase all current weather information from database // lastver = the last used version number in dword (using PLUGIN_MAKE_VERSION) @@ -182,167 +163,78 @@ void CWeatherProto::EraseAllInfo() ///////////////////////////////////////////////////////////////////////////////////////// -void CWeatherProto::ConvertDataValue(WIDATAITEM *UpdateData, wchar_t *Data) +static wchar_t rumbs[][16] = { L"N", L"NNE", L"NE", L"ENE", L"E", L"ESE", L"ES", L"SSE", L"S", L"SSW", L"SW", L"WSW", L"W", L"WNW", L"WN", L"NNW" }; + +static wchar_t *degree2str(double angle) { - wchar_t str[MAX_DATA_LEN]; + double a = 11.25; - // convert the unit - if (mir_wstrcmp(Data, TranslateT("<Error>")) && mir_wstrcmp(Data, NODATA) && mir_wstrcmp(Data, TranslateW(NODATA))) { - // temperature - if (!mir_wstrcmp(UpdateData->Name, L"Temperature") || !mir_wstrcmp(UpdateData->Name, L"High") || - !mir_wstrcmp(UpdateData->Name, L"Low") || !mir_wstrcmp(UpdateData->Name, L"Feel") || - !mir_wstrcmp(UpdateData->Name, L"Dew point") || - !mir_wstrcmpi(UpdateData->Unit, L"C") || !mir_wstrcmpi(UpdateData->Unit, L"F") || - !mir_wstrcmpi(UpdateData->Unit, L"K")) { - GetTemp(Data, UpdateData->Unit, str); - mir_wstrcpy(Data, str); - } - // pressure - else if (!mir_wstrcmp(UpdateData->Name, L"Pressure") || !mir_wstrcmpi(UpdateData->Unit, L"HPA") || - !mir_wstrcmpi(UpdateData->Unit, L"KPA") || !mir_wstrcmpi(UpdateData->Unit, L"MB") || - !mir_wstrcmpi(UpdateData->Unit, L"TORR") || !mir_wstrcmpi(UpdateData->Unit, L"IN") || - !mir_wstrcmpi(UpdateData->Unit, L"MM")) { - GetPressure(Data, UpdateData->Unit, str); - mir_wstrcpy(Data, str); - } - // speed - else if (!mir_wstrcmp(UpdateData->Name, L"Wind Speed") || !mir_wstrcmpi(UpdateData->Unit, L"KM/H") || - !mir_wstrcmpi(UpdateData->Unit, L"M/S") || !mir_wstrcmpi(UpdateData->Unit, L"MPH") || - !mir_wstrcmpi(UpdateData->Unit, L"KNOTS")) { - GetSpeed(Data, UpdateData->Unit, str); - mir_wstrcpy(Data, str); - } - // visibility - else if (!mir_wstrcmp(UpdateData->Name, L"Visibility") || !mir_wstrcmpi(UpdateData->Unit, L"KM") || - !mir_wstrcmpi(UpdateData->Unit, L"MILES")) { - GetDist(Data, UpdateData->Unit, str); - mir_wstrcpy(Data, str); - } - // elevation - else if (!mir_wstrcmp(UpdateData->Name, L"Elevation") || !mir_wstrcmpi(UpdateData->Unit, L"FT") || - !mir_wstrcmpi(UpdateData->Unit, L"M")) { - GetElev(Data, UpdateData->Unit, str); - mir_wstrcpy(Data, str); - } - // converting case for condition to the upper+lower format - else if (!mir_wstrcmpi(UpdateData->Unit, L"COND")) - CaseConv(Data); - // degree sign - else if (!mir_wstrcmpi(UpdateData->Unit, L"DEG")) { - if (!opt.DoNotAppendUnit) mir_wstrcat(Data, opt.DegreeSign); - } - // percent sign - else if (!mir_wstrcmpi(UpdateData->Unit, L"%")) { - if (!opt.DoNotAppendUnit) mir_wstrcat(Data, L"%"); - } - // truncating strings for day/month to 2 or 3 characters - else if (!mir_wstrcmpi(UpdateData->Unit, L"DAY") || !mir_wstrcmpi(UpdateData->Unit, L"MONTH")) - if (opt.dUnit > 1 && mir_wstrlen(Data) > opt.dUnit) - Data[opt.dUnit] = '\0'; - } -} + for (int i = 0; i < _countof(rumbs); i++, a += 22.5) + if (angle < a) + return rumbs[i]; -///////////////////////////////////////////////////////////////////////////////////////// -// get the value of the data using the start, end strings -// UpdateData = the WIDATAITEM struct containing start, end, unit -// Data = the string containing weather data obtained from UpdateData -// global var. used: szInfo = the downloaded string + // area between 348.75 & 360 degrees + return L"N"; +} -void CWeatherProto::GetDataValue(WIDATAITEM *UpdateData, wchar_t *Data, wchar_t **szData) +void CWeatherProto::ConvertDataValue(WIDATAITEM *p) { - wchar_t last = 0, current, *start, *end; - unsigned startloc = 0, endloc = 0, respos = 0; - BOOL tag = FALSE, symb = FALSE; - wchar_t *szInfo = *szData; - - Data[0] = 0; - // parse the data if available - if (UpdateData->Start[0] == 0 && UpdateData->End[0] == 0) return; - start = szInfo; - // the start string must be found - if (UpdateData->Start[0] != 0) { - start = wcsstr(szInfo, UpdateData->Start); - if (start != nullptr) { - // set the starting location for getting data - start += mir_wstrlen(UpdateData->Start); - szInfo = start; - } - } + wchar_t str[MAX_DATA_LEN]; - // the end string must be found too - if (UpdateData->End[0] != 0) - end = wcsstr(szInfo, UpdateData->End); - else - end = wcschr(szInfo, ' '); - - if (end != nullptr) { - // set the ending location - startloc = 0; - endloc = end - szInfo; - end += mir_wstrlen(UpdateData->End); - last = '\n'; + // temperature + if (!mir_wstrcmp(p->Name, L"Temperature") || !mir_wstrcmp(p->Name, L"High") || + !mir_wstrcmp(p->Name, L"Low") || !mir_wstrcmp(p->Name, L"Feel") || + !mir_wstrcmp(p->Name, L"Dew point") || + !mir_wstrcmpi(p->Unit, L"C") || !mir_wstrcmpi(p->Unit, L"F") || + !mir_wstrcmpi(p->Unit, L"K")) { + GetTemp(p->Value, p->Unit, str); + p->Value = str; } - - // ignore if not both of the string found - this prevent crashes - if (start != nullptr && end != nullptr) { - // begin reading the data from start location to end location - // remove all HTML tag in between, as well as leading space, ending space, - // multiple spaces, tabs, and return key - while (startloc < endloc) { - if (szInfo[startloc] == '<') tag = TRUE; - else if (szInfo[startloc] == '&' && - (szInfo[startloc + 1] == ';' || szInfo[startloc + 2] == ';' || szInfo[startloc + 3] == ';' || - szInfo[startloc + 4] == ';' || szInfo[startloc + 5] == ';' || szInfo[startloc + 6] == ';')) { - // ...but do NOT strip − - if ((endloc - startloc) > 7 && wcsncmp(szInfo + startloc, L"−", 7) == 0) { - Data[respos++] = '-'; - startloc += 7; - continue; - } - symb = TRUE; - } - else if (szInfo[startloc] == '>') tag = FALSE; - else if (szInfo[startloc] == ';') symb = FALSE; - else { - if (!tag && !symb) { - current = szInfo[startloc]; - if (current == '\n' || current == '\t' || current == ' ' || current == '\r') - current = ' '; - if (current != ' ' || last != ' ') { - if (last != '\n' && (respos != 0 || (respos == 0 && last != ' '))) - Data[respos++] = last; - last = current; - } - } - } - ++startloc; - // prevent crashes if the string go over maximun length -> generate an error - if (respos >= MAX_DATA_LEN) { - if (opt.ShowWarnings && UpdateData->Name[0] != 0 && mir_wstrcmp(UpdateData->Name, L"Ignore")) { - mir_snwprintf(Data, MAX_DATA_LEN, TranslateT("Error when obtaining data: %s"), UpdateData->Name); - WPShowMessage(Data, SM_WARNING); - } - wcsncpy(Data, TranslateT("<Error>"), MAX_DATA_LEN); - last = ' '; - respos = MAX_DATA_LEN - 1; - break; - } - } - - // get the last character - if (last != ' ') - Data[respos++] = last; - - // null terminate the string - Data[respos] = 0; - - // convert the unit - ConvertDataValue(UpdateData, Data); - - // remove the string before the data from szInfo - szInfo = end; + // pressure + else if (!mir_wstrcmp(p->Name, L"Pressure") || !mir_wstrcmpi(p->Unit, L"HPA") || + !mir_wstrcmpi(p->Unit, L"KPA") || !mir_wstrcmpi(p->Unit, L"MB") || + !mir_wstrcmpi(p->Unit, L"TORR") || !mir_wstrcmpi(p->Unit, L"IN") || + !mir_wstrcmpi(p->Unit, L"MM")) { + GetPressure(p->Value, p->Unit, str); + p->Value = str; + } + // speed + else if (!mir_wstrcmp(p->Name, L"Wind Speed") || !mir_wstrcmpi(p->Unit, L"KM/H") || + !mir_wstrcmpi(p->Unit, L"M/S") || !mir_wstrcmpi(p->Unit, L"MPH") || + !mir_wstrcmpi(p->Unit, L"KNOTS")) { + GetSpeed(p->Value, p->Unit, str); + p->Value = str; + } + // visibility + else if (!mir_wstrcmp(p->Name, L"Visibility") || !mir_wstrcmpi(p->Unit, L"KM") || + !mir_wstrcmpi(p->Unit, L"MILES")) { + GetDist(p->Value, p->Unit, str); + p->Value = str; + } + // elevation + else if (!mir_wstrcmp(p->Name, L"Elevation") || !mir_wstrcmpi(p->Unit, L"FT") || + !mir_wstrcmpi(p->Unit, L"M")) { + GetElev(p->Value, p->Unit, str); + p->Value = str; + } + // convert degrees to compass + else if (!mir_wstrcmpi(p->Unit, L"GRAD")) { + p->Value = degree2str(_wtof(p->Value)); + } + // degree sign + else if (!mir_wstrcmpi(p->Unit, L"DEG")) { + if (!opt.DoNotAppendUnit) + p->Value.Append(opt.DegreeSign); + } + // percent sign + else if (!mir_wstrcmpi(p->Unit, L"%")) { + if (!opt.DoNotAppendUnit) + p->Value.Append(L"%"); } - *szData = szInfo; + // truncating strings for day/month to 2 or 3 characters + else if (!mir_wstrcmpi(p->Unit, L"DAY") || !mir_wstrcmpi(p->Unit, L"MONTH")) + if (opt.dUnit > 1 && mir_wstrlen(p->Value) > opt.dUnit) + p->Value.SetAt(opt.dUnit, '\0'); } ///////////////////////////////////////////////////////////////////////////////////////// @@ -410,11 +302,11 @@ MHttpResponse* CWeatherProto::RunQuery(const wchar_t *id, int days) if (days) { time_t today = time(0); struct tm *p = localtime(&today); - pReq->m_szUrl.AppendFormat("%04d-%02d-%02d/", p->tm_year, p->tm_mon, p->tm_mday); + pReq->m_szUrl.AppendFormat("/%04d-%02d-%02d", p->tm_year + 1900, p->tm_mon + 1, p->tm_mday); today += 86400 * 7; // add one week p = localtime(&today); - pReq->m_szUrl.AppendFormat("%04d-%02d-%02d/", p->tm_year, p->tm_mon, p->tm_mday); + pReq->m_szUrl.AppendFormat("/%04d-%02d-%02d", p->tm_year + 1900, p->tm_mon + 1, p->tm_mday); } pReq << CHAR_PARAM("unitGroup", "metric") << WCHAR_PARAM("key", pKey) << CHAR_PARAM("contentType", "json"); diff --git a/protocols/Weather/src/weather_update.cpp b/protocols/Weather/src/weather_update.cpp index dfab7450eb..603afd16a5 100644 --- a/protocols/Weather/src/weather_update.cpp +++ b/protocols/Weather/src/weather_update.cpp @@ -351,34 +351,104 @@ INT_PTR CWeatherProto::UpdateAllRemove(WPARAM, LPARAM) // getting weather data and save them into the database // hContact = the contact to get the data +static wchar_t *moon2str(double phase) +{ + if (phase < 0.05) return TranslateT("New moon"); + if (phase < 0.26) return TranslateT("Waxing crescent"); + if (phase < 0.51) return TranslateT("Waxing gibbous"); + if (phase < 0.76) return TranslateT("Waning gibbous"); + return TranslateT("Waning crescent"); +} + +static void getData(OBJLIST<WIDATAITEM> &arValues, const JSONNode &node) +{ + arValues.insert(new WIDATAITEM(LPGENW("Condition"), L"", node["conditions"].as_mstring())); + arValues.insert(new WIDATAITEM(LPGENW("Temperature"), L"C", node["temp"].as_mstring())); + arValues.insert(new WIDATAITEM(LPGENW("High"), L"C", node["tempmax"].as_mstring())); + arValues.insert(new WIDATAITEM(LPGENW("Low"), L"C", node["tempmin"].as_mstring())); + arValues.insert(new WIDATAITEM(LPGENW("Sunset"), L"", node["sunset"].as_mstring())); + arValues.insert(new WIDATAITEM(LPGENW("Sunrise"), L"", node["sunrise"].as_mstring())); + arValues.insert(new WIDATAITEM(LPGENW("Moon phase"), L"", moon2str(node["moonphase"].as_float()))); + arValues.insert(new WIDATAITEM(LPGENW("Wind speed"), L"km/h", node["windspeed"].as_mstring())); + arValues.insert(new WIDATAITEM(LPGENW("Wind direction"), L"grad", node["winddir"].as_mstring())); + arValues.insert(new WIDATAITEM(LPGENW("Dew point"), L"C", node["dew"].as_mstring())); + arValues.insert(new WIDATAITEM(LPGENW("Pressure"), L"mb", node["pressure"].as_mstring())); + arValues.insert(new WIDATAITEM(LPGENW("Visibility"), L"km", node["visibility"].as_mstring())); + arValues.insert(new WIDATAITEM(LPGENW("Humidity"), L"", node["humidity"].as_mstring())); + arValues.insert(new WIDATAITEM(LPGENW("Feel"), L"C", node["feelslike"].as_mstring())); +} + int CWeatherProto::GetWeatherData(MCONTACT hContact) { // get each part of the id's wchar_t id[256]; GetStationID(hContact, id, _countof(id)); - - wchar_t Svc[256]; - GetStationID(hContact, Svc, _countof(Svc)); - - // check for invalid station - if (id[0] == 0) return INVALID_ID; - if (Svc[0] == 0) return INVALID_SVC; + if (id[0] == 0) + return INVALID_ID; uint16_t cond = NA; // download the html file from the internet - wchar_t *szData = nullptr; - int retval = 1; // InternetDownloadFile(loc, 0, 0, &szData); - if (retval != 0) { - mir_free(szData); - return retval; - } - if (wcsstr(szData, L"Document Not Found") != nullptr) { - mir_free(szData); - return DOC_NOT_FOUND; + JsonReply reply(RunQuery(id, 7)); + if (!reply) + return reply.error(); + + auto &root = reply.data(); + + // writing current conditions + auto &curr = root["currentConditions"]; + OBJLIST<WIDATAITEM> arValues(20); + arValues.insert(new WIDATAITEM(L"Update", L"", curr["datetime"].as_mstring())); + getData(arValues, curr); + + auto szIcon = curr["icon"].as_string(); + if (szIcon == "snow") + cond = SNOW; + else if (szIcon == "snow-showers-day" || szIcon == "snow-showers-night") + cond = SSHOWER; + else if (szIcon == "thunder" || szIcon == "thunder-showers-day" || szIcon == "thunder-showers-night") + cond = LIGHT; + else if (szIcon == "partly-cloudy-day" || szIcon == "partly-cloudy-night" || szIcon == "wind") + cond = PCLOUDY; + else if (szIcon == "fog") + cond = FOG; + else if (szIcon == "rain") + cond = RAIN; + else if (szIcon == "showers-day" || szIcon == "showers-night") + cond = RSHOWER; + else if (szIcon == "clear-day" || szIcon == "clear-night") + cond = SUNNY; + else if (szIcon == "rain") + cond = RAIN; + else if (szIcon == "cloudy") + cond = CLOUDY; + + for (auto &it : arValues) { + ConvertDataValue(it); + db_set_ws(hContact, WEATHERCONDITION, _T2A(it->Name), it->Value); } - mir_free(szData); + // writing forecast + int iFore = 0; + for (auto &fore : root["days"]) { + arValues.destroy(); + arValues.insert(new WIDATAITEM(L"Update", L"", fore["datetime"].as_mstring())); + getData(arValues, fore); + + CMStringW result; + for (auto &it : arValues) { + ConvertDataValue(it); + if (it->Value.IsEmpty()) + continue; + + if (!result.IsEmpty()) + result += L"; "; + result.AppendFormat(L"%s - %s", TranslateW(it->Name), it->Value.c_str()); + } + + CMStringA szSetting(FORMAT, "Forecast Day %d", iFore++); + db_set_ws(hContact, WEATHERCONDITION, szSetting, result); + } // assign condition icon setWord(hContact, "StatusIcon", cond); |
