diff options
author | Alberts Muktupāvels <alberts.muktupavels@gmail.com> | 2018-04-30 14:14:09 +0300 |
---|---|---|
committer | Alberts Muktupāvels <alberts.muktupavels@gmail.com> | 2018-04-30 14:14:09 +0300 |
commit | 2a2aface6fddf173e48f4e86a8e2d6941a7498cc (patch) | |
tree | 53ea4c88930cc08a91551acda14c0c2c00d8f66a | |
parent | e768f098c918573995dfaaa450e5f25cb159731e (diff) | |
download | libgweather-wip/muktupavels/fix-metar-data.tar.gz |
weather-metar: properly extract metar datawip/muktupavels/fix-metar-data
Commit 283afc2d23355def1c1bab70a641f40cea52ba7f switched to new
METAR data provider, but did not fully update code to properly
extract METAR data.
The code still assumes that data are separated by newlines. That
means that now extracted data includes part of opening raw_text
tag, location code and closing raw_text tag.
Fix this by moving pointer to correct position to make sure that
xml tag and location code is not included. Also search for
closing tag to exclude it from data.
Before:
ext>EVRA 241450Z 22011KT 9999 -SHRA SCT034CB OVC039 11/05 Q1005 NOSIG</raw_text>\u000d
After:
241450Z 22011KT 9999 -SHRA SCT034CB OVC039 11/05 Q1005 NOSIG
-rw-r--r-- | libgweather/weather-metar.c | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/libgweather/weather-metar.c b/libgweather/weather-metar.c index 31ef815..aeb65ad 100644 --- a/libgweather/weather-metar.c +++ b/libgweather/weather-metar.c @@ -588,12 +588,12 @@ metar_finish (SoupSession *session, SoupMessage *msg, gpointer data) loc = &priv->location; - searchkey = g_strdup_printf ("<raw_text>%s", loc->code); + searchkey = g_strdup_printf ("<raw_text>%s ", loc->code); p = strstr (msg->response_body->data, searchkey); - g_free (searchkey); + if (p) { - p += WEATHER_LOCATION_CODE_LEN + 2; - eoln = strchr(p, '\n'); + p += strlen (searchkey); + eoln = strstr (p, "</raw_text>"); if (eoln) metar = g_strndup (p, eoln - p); else @@ -608,6 +608,8 @@ metar_finish (SoupSession *session, SoupMessage *msg, gpointer data) priv->network_error = TRUE; } + g_free (searchkey); + priv->valid = success; _gweather_info_request_done (info, msg); } |