[libgweather/benzea/gnome-3-36-met.no-backport: 8/10] metno: Use alphabetical 2.0 symbol codes




commit b7e8f9c1b2844035c33c7e7cc30166c1449b51db
Author: Florian Müllner <fmuellner gnome org>
Date:   Thu Jan 21 05:12:21 2021 +0100

    metno: Use alphabetical 2.0 symbol codes
    
    The numerical codes are deprecated and scheduled for removal, so
    replace them with the non-deprecated alphabetical codes as listed
    in https://api.met.no/weatherapi/weathericon/2.0/.
    
    https://gitlab.gnome.org/GNOME/libgweather/-/issues/67

 libgweather/weather-yrno.c | 111 ++++++++++++++++++++++-----------------------
 1 file changed, 54 insertions(+), 57 deletions(-)
---
diff --git a/libgweather/weather-yrno.c b/libgweather/weather-yrno.c
index 06c10822..ba6aa80e 100644
--- a/libgweather/weather-yrno.c
+++ b/libgweather/weather-yrno.c
@@ -42,53 +42,53 @@
 
 /* Reference for symbols at https://api.met.no/weatherapi/weathericon/2.0/ */
 typedef struct {
-    int code;
+    const char *code;
     GWeatherSky sky;
     GWeatherConditions condition;
 } YrnoSymbol;
 
 static YrnoSymbol symbols[] = {
-    { 1,  GWEATHER_SKY_CLEAR,     { FALSE, GWEATHER_PHENOMENON_NONE, GWEATHER_QUALIFIER_NONE } }, /* Sun */
-    { 2,  GWEATHER_SKY_BROKEN,    { FALSE, GWEATHER_PHENOMENON_NONE, GWEATHER_QUALIFIER_NONE } }, /* 
LightCloud */
-    { 3,  GWEATHER_SKY_SCATTERED, { FALSE, GWEATHER_PHENOMENON_NONE, GWEATHER_QUALIFIER_NONE } }, /* 
PartlyCloudy */
-    { 4,  GWEATHER_SKY_OVERCAST,  { FALSE, GWEATHER_PHENOMENON_NONE, GWEATHER_QUALIFIER_NONE } }, /* Cloudy 
*/
-    { 5,  GWEATHER_SKY_BROKEN,    { TRUE, GWEATHER_PHENOMENON_RAIN, GWEATHER_QUALIFIER_LIGHT } }, /* 
LightRainSun */
-    { 6,  GWEATHER_SKY_BROKEN,    { TRUE, GWEATHER_PHENOMENON_RAIN, GWEATHER_QUALIFIER_THUNDERSTORM } }, /* 
LightRainThunderSun */
-    { 7,  GWEATHER_SKY_BROKEN,    { TRUE, GWEATHER_PHENOMENON_ICE_PELLETS, GWEATHER_QUALIFIER_NONE } }, /* 
SleetSun */
-    { 8,  GWEATHER_SKY_BROKEN,    { TRUE, GWEATHER_PHENOMENON_SNOW, GWEATHER_QUALIFIER_NONE } }, /* SnowSun 
*/
-    { 9,  GWEATHER_SKY_OVERCAST,  { TRUE, GWEATHER_PHENOMENON_RAIN, GWEATHER_QUALIFIER_LIGHT } }, /* SnowSun 
*/
-    { 10, GWEATHER_SKY_OVERCAST,  { TRUE, GWEATHER_PHENOMENON_RAIN, GWEATHER_QUALIFIER_NONE } }, /* Rain */
-    { 11, GWEATHER_SKY_OVERCAST,  { TRUE, GWEATHER_PHENOMENON_RAIN, GWEATHER_QUALIFIER_THUNDERSTORM } }, /* 
RainThunder */
-    { 12, GWEATHER_SKY_OVERCAST,  { TRUE, GWEATHER_PHENOMENON_ICE_PELLETS, GWEATHER_QUALIFIER_NONE } }, /* 
Sleet */
-    { 13, GWEATHER_SKY_OVERCAST,  { TRUE, GWEATHER_PHENOMENON_SNOW, GWEATHER_QUALIFIER_NONE } }, /* Snow */
-    { 14, GWEATHER_SKY_OVERCAST,  { TRUE, GWEATHER_PHENOMENON_SNOW, GWEATHER_QUALIFIER_THUNDERSTORM } }, /* 
SnowThunder */
-    { 15, GWEATHER_SKY_CLEAR,     { TRUE, GWEATHER_PHENOMENON_FOG, GWEATHER_QUALIFIER_NONE } }, /* Fog */
-    { 20, GWEATHER_SKY_BROKEN,    { TRUE, GWEATHER_PHENOMENON_ICE_PELLETS, GWEATHER_QUALIFIER_THUNDERSTORM } 
}, /* SleetSunThunder */
-    { 21, GWEATHER_SKY_BROKEN,    { TRUE, GWEATHER_PHENOMENON_SNOW, GWEATHER_QUALIFIER_THUNDERSTORM } }, /* 
SnowSunThunder */
-    { 22, GWEATHER_SKY_OVERCAST,  { TRUE, GWEATHER_PHENOMENON_RAIN, GWEATHER_QUALIFIER_THUNDERSTORM } }, /* 
LightRainThunder */
-    { 23, GWEATHER_SKY_OVERCAST,  { TRUE, GWEATHER_PHENOMENON_ICE_PELLETS, GWEATHER_QUALIFIER_THUNDERSTORM } 
}, /* SleetThunder */
-    { 24, GWEATHER_SKY_BROKEN,  { TRUE, GWEATHER_PHENOMENON_DRIZZLE, GWEATHER_QUALIFIER_THUNDERSTORM } }, /* 
DrizzleThunderSun */
-    { 25, GWEATHER_SKY_BROKEN,  { TRUE, GWEATHER_PHENOMENON_RAIN, GWEATHER_QUALIFIER_THUNDERSTORM } }, /* 
RainThunderSun */
-    { 26, GWEATHER_SKY_BROKEN,    { TRUE, GWEATHER_PHENOMENON_ICE_PELLETS, GWEATHER_QUALIFIER_LIGHT } }, /* 
LightSleetThunderSun */
-    { 27, GWEATHER_SKY_BROKEN,    { TRUE, GWEATHER_PHENOMENON_ICE_PELLETS, GWEATHER_QUALIFIER_HEAVY } }, /* 
HeavySleetThunderSun */
-    { 28, GWEATHER_SKY_BROKEN,    { TRUE, GWEATHER_PHENOMENON_SNOW, GWEATHER_QUALIFIER_LIGHT } }, /* 
LightSnowThunderSun */
-    { 29, GWEATHER_SKY_BROKEN,    { TRUE, GWEATHER_PHENOMENON_SNOW, GWEATHER_QUALIFIER_HEAVY } }, /* 
HeavySnowThunderSun */
-    { 30, GWEATHER_SKY_OVERCAST,    { TRUE, GWEATHER_PHENOMENON_DRIZZLE, GWEATHER_QUALIFIER_THUNDERSTORM } 
}, /* DrizzleThunder */
-    { 31, GWEATHER_SKY_OVERCAST,    { TRUE, GWEATHER_PHENOMENON_ICE_PELLETS, GWEATHER_QUALIFIER_LIGHT } }, 
/* LightSleetThunder */
-    { 32, GWEATHER_SKY_OVERCAST,    { TRUE, GWEATHER_PHENOMENON_ICE_PELLETS, GWEATHER_QUALIFIER_HEAVY } }, 
/* HeavySleetThunder */
-    { 33, GWEATHER_SKY_OVERCAST,    { TRUE, GWEATHER_PHENOMENON_SNOW, GWEATHER_QUALIFIER_LIGHT } }, /* 
LightSnowThunder */
-    { 34, GWEATHER_SKY_OVERCAST,    { TRUE, GWEATHER_PHENOMENON_SNOW, GWEATHER_QUALIFIER_HEAVY } }, /* 
HeavySnowThunder */
-    { 40, GWEATHER_SKY_BROKEN,    { TRUE, GWEATHER_PHENOMENON_DRIZZLE, GWEATHER_QUALIFIER_NONE } }, /* 
DrizzleSun */
-    { 41, GWEATHER_SKY_BROKEN,    { TRUE, GWEATHER_PHENOMENON_RAIN, GWEATHER_QUALIFIER_NONE } }, /* RainSun 
*/
-    { 42, GWEATHER_SKY_BROKEN,    { TRUE, GWEATHER_PHENOMENON_ICE_PELLETS, GWEATHER_QUALIFIER_LIGHT } }, /* 
LightSleetSun */
-    { 43, GWEATHER_SKY_BROKEN,    { TRUE, GWEATHER_PHENOMENON_ICE_PELLETS, GWEATHER_QUALIFIER_HEAVY } }, /* 
HeavySleetSun */
-    { 44, GWEATHER_SKY_BROKEN,    { TRUE, GWEATHER_PHENOMENON_SNOW, GWEATHER_QUALIFIER_LIGHT } }, /* 
LightSnowSun */
-    { 45, GWEATHER_SKY_BROKEN,    { TRUE, GWEATHER_PHENOMENON_SNOW, GWEATHER_QUALIFIER_HEAVY } }, /* 
HeavySnowSun */
-    { 46, GWEATHER_SKY_OVERCAST,    { TRUE, GWEATHER_PHENOMENON_DRIZZLE, GWEATHER_QUALIFIER_NONE } }, /* 
Drizzle */
-    { 47, GWEATHER_SKY_OVERCAST,    { TRUE, GWEATHER_PHENOMENON_ICE_PELLETS, GWEATHER_QUALIFIER_LIGHT } }, 
/* LightSleet */
-    { 48, GWEATHER_SKY_OVERCAST,    { TRUE, GWEATHER_PHENOMENON_ICE_PELLETS, GWEATHER_QUALIFIER_HEAVY } }, 
/* HeavySleet */
-    { 49, GWEATHER_SKY_OVERCAST,    { TRUE, GWEATHER_PHENOMENON_SNOW, GWEATHER_QUALIFIER_LIGHT } }, /* 
LightSnow */
-    { 50, GWEATHER_SKY_OVERCAST,    { TRUE, GWEATHER_PHENOMENON_SNOW, GWEATHER_QUALIFIER_HEAVY } } /* 
HeavySnow */
+    { "clearsky",  GWEATHER_SKY_CLEAR,     { FALSE, GWEATHER_PHENOMENON_NONE, GWEATHER_QUALIFIER_NONE } }, 
/* Sun */
+    { "fair",  GWEATHER_SKY_BROKEN,    { FALSE, GWEATHER_PHENOMENON_NONE, GWEATHER_QUALIFIER_NONE } }, /* 
LightCloud */
+    { "partlycloudy",  GWEATHER_SKY_SCATTERED, { FALSE, GWEATHER_PHENOMENON_NONE, GWEATHER_QUALIFIER_NONE } 
}, /* PartlyCloudy */
+    { "cloudy",  GWEATHER_SKY_OVERCAST,  { FALSE, GWEATHER_PHENOMENON_NONE, GWEATHER_QUALIFIER_NONE } }, /* 
Cloudy */
+    { "rainshowers",  GWEATHER_SKY_BROKEN,    { TRUE, GWEATHER_PHENOMENON_RAIN, GWEATHER_QUALIFIER_LIGHT } 
}, /* LightRainSun */
+    { "rainshowersandthunder",  GWEATHER_SKY_BROKEN,    { TRUE, GWEATHER_PHENOMENON_RAIN, 
GWEATHER_QUALIFIER_THUNDERSTORM } }, /* LightRainThunderSun */
+    { "sleetshowers",  GWEATHER_SKY_BROKEN,    { TRUE, GWEATHER_PHENOMENON_ICE_PELLETS, 
GWEATHER_QUALIFIER_NONE } }, /* SleetSun */
+    { "snowshowers",  GWEATHER_SKY_BROKEN,    { TRUE, GWEATHER_PHENOMENON_SNOW, GWEATHER_QUALIFIER_NONE } }, 
/* SnowSun */
+    { "rain",  GWEATHER_SKY_OVERCAST,  { TRUE, GWEATHER_PHENOMENON_RAIN, GWEATHER_QUALIFIER_LIGHT } }, /* 
SnowSun */
+    { "heavyrain", GWEATHER_SKY_OVERCAST,  { TRUE, GWEATHER_PHENOMENON_RAIN, GWEATHER_QUALIFIER_NONE } }, /* 
Rain */
+    { "heavyrainandthunder", GWEATHER_SKY_OVERCAST,  { TRUE, GWEATHER_PHENOMENON_RAIN, 
GWEATHER_QUALIFIER_THUNDERSTORM } }, /* RainThunder */
+    { "sleet", GWEATHER_SKY_OVERCAST,  { TRUE, GWEATHER_PHENOMENON_ICE_PELLETS, GWEATHER_QUALIFIER_NONE } }, 
/* Sleet */
+    { "snow", GWEATHER_SKY_OVERCAST,  { TRUE, GWEATHER_PHENOMENON_SNOW, GWEATHER_QUALIFIER_NONE } }, /* Snow 
*/
+    { "snowandthunder", GWEATHER_SKY_OVERCAST,  { TRUE, GWEATHER_PHENOMENON_SNOW, 
GWEATHER_QUALIFIER_THUNDERSTORM } }, /* SnowThunder */
+    { "fog", GWEATHER_SKY_CLEAR,     { TRUE, GWEATHER_PHENOMENON_FOG, GWEATHER_QUALIFIER_NONE } }, /* Fog */
+    { "sleetshowersandthunder", GWEATHER_SKY_BROKEN,    { TRUE, GWEATHER_PHENOMENON_ICE_PELLETS, 
GWEATHER_QUALIFIER_THUNDERSTORM } }, /* SleetSunThunder */
+    { "snowshowersandthunder", GWEATHER_SKY_BROKEN,    { TRUE, GWEATHER_PHENOMENON_SNOW, 
GWEATHER_QUALIFIER_THUNDERSTORM } }, /* SnowSunThunder */
+    { "rainandthunder", GWEATHER_SKY_OVERCAST,  { TRUE, GWEATHER_PHENOMENON_RAIN, 
GWEATHER_QUALIFIER_THUNDERSTORM } }, /* LightRainThunder */
+    { "sleetandthunder", GWEATHER_SKY_OVERCAST,  { TRUE, GWEATHER_PHENOMENON_ICE_PELLETS, 
GWEATHER_QUALIFIER_THUNDERSTORM } }, /* SleetThunder */
+    { "lightrainshowersandthunder", GWEATHER_SKY_BROKEN,  { TRUE, GWEATHER_PHENOMENON_DRIZZLE, 
GWEATHER_QUALIFIER_THUNDERSTORM } }, /* DrizzleThunderSun */
+    { "heavyrainshowersandthunder", GWEATHER_SKY_BROKEN,  { TRUE, GWEATHER_PHENOMENON_RAIN, 
GWEATHER_QUALIFIER_THUNDERSTORM } }, /* RainThunderSun */
+    { "lightssleetshowersandthunder", GWEATHER_SKY_BROKEN,    { TRUE, GWEATHER_PHENOMENON_ICE_PELLETS, 
GWEATHER_QUALIFIER_LIGHT } }, /* LightSleetThunderSun */
+    { "heavysleetshowersandthunder", GWEATHER_SKY_BROKEN,    { TRUE, GWEATHER_PHENOMENON_ICE_PELLETS, 
GWEATHER_QUALIFIER_HEAVY } }, /* HeavySleetThunderSun */
+    { "lightssnowshowersandthunder", GWEATHER_SKY_BROKEN,    { TRUE, GWEATHER_PHENOMENON_SNOW, 
GWEATHER_QUALIFIER_LIGHT } }, /* LightSnowThunderSun */
+    { "heavysnowshowersandthunder", GWEATHER_SKY_BROKEN,    { TRUE, GWEATHER_PHENOMENON_SNOW, 
GWEATHER_QUALIFIER_HEAVY } }, /* HeavySnowThunderSun */
+    { "lightrainandthunder", GWEATHER_SKY_OVERCAST,    { TRUE, GWEATHER_PHENOMENON_DRIZZLE, 
GWEATHER_QUALIFIER_THUNDERSTORM } }, /* DrizzleThunder */
+    { "lightsleetandthunder", GWEATHER_SKY_OVERCAST,    { TRUE, GWEATHER_PHENOMENON_ICE_PELLETS, 
GWEATHER_QUALIFIER_LIGHT } }, /* LightSleetThunder */
+    { "heavysleetandthunder", GWEATHER_SKY_OVERCAST,    { TRUE, GWEATHER_PHENOMENON_ICE_PELLETS, 
GWEATHER_QUALIFIER_HEAVY } }, /* HeavySleetThunder */
+    { "lightsnowandthunder", GWEATHER_SKY_OVERCAST,    { TRUE, GWEATHER_PHENOMENON_SNOW, 
GWEATHER_QUALIFIER_LIGHT } }, /* LightSnowThunder */
+    { "heavysnowandthunder", GWEATHER_SKY_OVERCAST,    { TRUE, GWEATHER_PHENOMENON_SNOW, 
GWEATHER_QUALIFIER_HEAVY } }, /* HeavySnowThunder */
+    { "lightrainshowers", GWEATHER_SKY_BROKEN,    { TRUE, GWEATHER_PHENOMENON_DRIZZLE, 
GWEATHER_QUALIFIER_NONE } }, /* DrizzleSun */
+    { "heavyrainshowers", GWEATHER_SKY_BROKEN,    { TRUE, GWEATHER_PHENOMENON_RAIN, GWEATHER_QUALIFIER_NONE 
} }, /* RainSun */
+    { "lightsleetshowers", GWEATHER_SKY_BROKEN,    { TRUE, GWEATHER_PHENOMENON_ICE_PELLETS, 
GWEATHER_QUALIFIER_LIGHT } }, /* LightSleetSun */
+    { "heavysleetshowers", GWEATHER_SKY_BROKEN,    { TRUE, GWEATHER_PHENOMENON_ICE_PELLETS, 
GWEATHER_QUALIFIER_HEAVY } }, /* HeavySleetSun */
+    { "lightsnowshowers", GWEATHER_SKY_BROKEN,    { TRUE, GWEATHER_PHENOMENON_SNOW, GWEATHER_QUALIFIER_LIGHT 
} }, /* LightSnowSun */
+    { "heavysnowshowers", GWEATHER_SKY_BROKEN,    { TRUE, GWEATHER_PHENOMENON_SNOW, GWEATHER_QUALIFIER_HEAVY 
} }, /* HeavySnowSun */
+    { "lightrain", GWEATHER_SKY_OVERCAST,    { TRUE, GWEATHER_PHENOMENON_DRIZZLE, GWEATHER_QUALIFIER_NONE } 
}, /* Drizzle */
+    { "lightsleet", GWEATHER_SKY_OVERCAST,    { TRUE, GWEATHER_PHENOMENON_ICE_PELLETS, 
GWEATHER_QUALIFIER_LIGHT } }, /* LightSleet */
+    { "heavysleet", GWEATHER_SKY_OVERCAST,    { TRUE, GWEATHER_PHENOMENON_ICE_PELLETS, 
GWEATHER_QUALIFIER_HEAVY } }, /* HeavySleet */
+    { "lightsnow", GWEATHER_SKY_OVERCAST,    { TRUE, GWEATHER_PHENOMENON_SNOW, GWEATHER_QUALIFIER_LIGHT } }, 
/* LightSnow */
+    { "heavysnow", GWEATHER_SKY_OVERCAST,    { TRUE, GWEATHER_PHENOMENON_SNOW, GWEATHER_QUALIFIER_HEAVY } } 
/* HeavySnow */
 };
 
 static struct {
@@ -151,19 +151,16 @@ date_to_time_t (const xmlChar *str, const char * tzid)
 static YrnoSymbol *
 symbol_search (int code)
 {
-    int a = 0;
-    int b = G_N_ELEMENTS (symbols);
-
-    while (a < b) {
-       int c = (a + b)/2;
-       YrnoSymbol *yc = symbols + c;
-
-       if (yc->code == code)
-           return yc;
-       if (yc->code < code)
-           a = c+1;
-       else
-           b = c;
+    unsigned int i;
+
+    for (i = 0; i < G_N_ELEMENTS (symbols); i++) {
+        MetnoSymbol *s = symbols + i;
+
+        if (strcmp (code, s->code) == 0)
+            return s;
+
+        if (strstr (code, s->code) == code && code[strlen (s->code)] == '_')
+            return s;
     }
 
     return NULL;
@@ -177,9 +174,9 @@ read_symbol (GWeatherInfo *info,
     YrnoSymbol* symbol;
     GWeatherInfoPrivate *priv = info->priv;
 
-    val = xmlGetProp (node, XC("number"));
+    val = xmlGetProp (node, XC("code"));
 
-    symbol = symbol_search (strtol ((char*) val, NULL, 0));
+    symbol = symbol_search ((char *)val);
     if (symbol != NULL) {
        priv->valid = TRUE;
        priv->sky = symbol->sky;


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]