summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorawy <awy@awy.one>2025-08-24 13:37:48 +0300
committerawy <awy@awy.one>2025-08-24 13:37:48 +0300
commit9be08523c72dc95c48e1077758001580346a49e8 (patch)
treef793ddf273e5bfbcedee01c7224d903e7972b585
parent66d39ce2e04ea14d9d9636ae203bec4c39932b0c (diff)
stweath
-rw-r--r--src/stweath.c87
1 files changed, 31 insertions, 56 deletions
diff --git a/src/stweath.c b/src/stweath.c
index 6e5bef3..c28f48d 100644
--- a/src/stweath.c
+++ b/src/stweath.c
@@ -23,6 +23,35 @@
#include <unistd.h>
#include "cjson/cJSON.h"
+typedef struct {
+ int code;
+ const char *icon;
+} WeatherIcon;
+
+const char
+*geticon(int code)
+{
+ static const WeatherIcon icons[] = {
+ {113, ""},
+ {116, ""},
+ {119, ""}, {122, ""}, {143, ""}, {248, ""}, {260, ""},
+ {176, ""}, {179, ""}, {182, ""}, {185, ""}, {263, ""},
+ {266, ""}, {281, ""}, {284, ""}, {293, ""}, {296, ""},
+ {299, ""}, {302, ""}, {305, ""}, {308, ""}, {311, ""},
+ {314, ""}, {317, ""}, {350, ""}, {353, ""}, {356, ""},
+ {359, ""}, {362, ""}, {365, ""}, {368, ""}, {392, ""},
+ {200, ""},
+ {227, ""}, {230, ""}, {320, ""}, {323, ""}, {326, ""},
+ {374, ""}, {377, ""}, {386, ""}, {389, ""},
+ {329, ""}, {332, ""}, {335, ""}, {338, ""}, {371, ""}, {395, ""}
+ };
+ size_t n = sizeof(icons) / sizeof(icons[0]);
+ for (size_t i = 0; i < n; i++) {
+ if (icons[i].code == code) { return icons[i].icon; }
+ }
+ return "unknown";
+}
+
int
getforecast(char *path)
{
@@ -62,7 +91,7 @@ showforecast(char *path)
{
long size;
char *data;
- char *icon;
+ const char *icon;
cJSON *root, *temp, *wcode, *rain;
FILE *report;
@@ -95,61 +124,7 @@ showforecast(char *path)
wcode = cJSON_GetObjectItem(temp, "weatherCode");
temp = cJSON_GetObjectItem(temp, "temp_C");
- switch (atoi(wcode->valuestring)) {
- case 113: icon = ""; break;
- case 116: icon = ""; break;
- case 119:
- case 122:
- case 143:
- case 248:
- case 260:
- icon = ""; break;
- case 176:
- case 179:
- case 182:
- case 185:
- case 263:
- case 266:
- case 281:
- case 284:
- case 293:
- case 296:
- case 299:
- case 302:
- case 305:
- case 308:
- case 311:
- case 314:
- case 317:
- case 350:
- case 353:
- case 356:
- case 359:
- case 362:
- case 365:
- case 368:
- case 392:
- icon = ""; break;
- case 200: icon = ""; break;
- case 227:
- case 230:
- case 320:
- case 323:
- case 326:
- case 374:
- case 377:
- case 386:
- case 389:
- icon = ""; break;
- case 329:
- case 332:
- case 335:
- case 338:
- case 371:
- case 395:
- icon = ""; break;
- default: icon = "❓"; break;
- }
+ icon = geticon(atoi(wcode->valuestring));
if (atoi(rain->valuestring) != 0) {
printf(" %s%% ", rain->valuestring);