summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVictor Kareh <[email protected]>2025-09-25 13:10:59 -0400
committerVictor Kareh <[email protected]>2025-09-30 18:16:32 +0000
commit145cb89942a942df25278f378006cff729520551 (patch)
treebf86907c0eef12a16b154cef312560f2932f7b55
parent0e881958caf4679dcd79e99e4f1a6f8464624e10 (diff)
downloadlibmateweather-master.tar.bz2
libmateweather-master.tar.xz
metar: Support SPECI report dataHEADmaster
Since AviationWeather updated their API, they now return two report types: METAR (standard hourly repors) and SPECI (special intermediate reports). We can parse those out from the response since the format is similar, and the only thing that changes is the prefix.
-rw-r--r--libmateweather/weather-metar.c16
1 files changed, 12 insertions, 4 deletions
diff --git a/libmateweather/weather-metar.c b/libmateweather/weather-metar.c
index dabca3a..d25a432 100644
--- a/libmateweather/weather-metar.c
+++ b/libmateweather/weather-metar.c
@@ -523,15 +523,20 @@ metar_finish (GObject *source, GAsyncResult *result, gpointer data)
loc = info->location;
- searchkey = g_strdup_printf ("<raw_text>METAR %s", loc->code);
-
response_body = g_bytes_get_data (bytes, &len);
end = response_body + len;
+ /* Try METAR first, then SPECI */
+ searchkey = g_strdup_printf ("<raw_text>METAR %s", loc->code);
p = xstrnstr (response_body, len, searchkey);
+ if (!p) {
+ g_free (searchkey);
+ searchkey = g_strdup_printf ("<raw_text>SPECI %s", loc->code);
+ p = xstrnstr (response_body, len, searchkey);
+ }
+
if (p) {
p += WEATHER_LOCATION_CODE_LEN + 11;
- endtag = strstr (p, "</raw_text>");
endtag = xstrnstr (p, end - p, "</raw_text>");
if (endtag)
metar = g_strndup (p, endtag - p);
@@ -539,7 +544,10 @@ metar_finish (GObject *source, GAsyncResult *result, gpointer data)
metar = g_strndup (p, end - p);
success = metar_parse (metar, info);
g_free (metar);
- } else if (!xstrnstr (response_body, len, "aviationweather.gov")) {
+ }
+ g_free (searchkey);
+
+ if (!success && !xstrnstr (response_body, len, "aviationweather.gov")) {
/* The response doesn't even seem to have come from NOAA...
* most likely it is a wifi hotspot login page. Call that a
* network error.