diff options
author | Erich Eckner <git@eckner.net> | 2018-10-30 10:39:55 +0100 |
---|---|---|
committer | Erich Eckner <git@eckner.net> | 2018-10-31 21:48:36 +0100 |
commit | e3e7618f6dfc0ae997042cb22d9eee1dd8e19678 (patch) | |
tree | 6f6bf6b9c4fec7e38fa32092f51be3308c81bde0 /input_gadgets.c | |
parent | 4743e2a38c354669b7ac7f269a628aacfb38f02a (diff) | |
download | anzeige-e3e7618f6dfc0ae997042cb22d9eee1dd8e19678.tar.xz |
input_gadgets.c: parse date & time of fh temperature instead of copying fields
Diffstat (limited to 'input_gadgets.c')
-rw-r--r-- | input_gadgets.c | 41 |
1 files changed, 19 insertions, 22 deletions
diff --git a/input_gadgets.c b/input_gadgets.c index df0abe1..292a112 100644 --- a/input_gadgets.c +++ b/input_gadgets.c @@ -12,7 +12,7 @@ #include "input_gadgets.h" -#define fh_temperature_regex "<strong>\\s*\n\\s*Wetterdaten vom ([0-9]{2})\\.([0-9]{2})\\.([0-9]{4}) um ([0-9:]{5}) MEZ</strong>(.|\n)*>Temperatur</td>\\s*\n\\s*<td [^>]*><strong>([^<]*)</strong>" +#define fh_temperature_regex "<strong>\\s*\n\\s*Wetterdaten vom ([0-9]{2}\\.[0-9]{2}\\.[0-9]{4} um [0-9]{2}:[0-9]{2} MEZ)</strong>(.|\n)*>Temperatur</td>\\s*\n\\s*<td [^>]*><strong>([^<]*)</strong>" #define wetter_warnung_filename_regex "^2\\.49\\.0\\.1\\.276\\.0\\.DWD\\.PVW\\.([0-9]+)\\." #define warnings_future_timespan (60*60*10) @@ -153,15 +153,13 @@ char *gadgets_retrieve_current_temperature(char *output, int max_len) } regex_t re; - regmatch_t rm[7]; - if (regcomp(&re, fh_temperature_regex, REG_EXTENDED|REG_NEWLINE) != 0) - { + regmatch_t rm[4]; + if (regcomp(&re, fh_temperature_regex, REG_EXTENDED|REG_NEWLINE) != 0) { fprintf(stderr, "Failed to compile regex '%s'\n", fh_temperature_regex); free(chunk.memory); return NULL; } - if (ret_val = regexec(&re, chunk.memory, 7, rm, 0)) - { + if (ret_val = regexec(&re, chunk.memory, 4, rm, 0)) { char *reg_err; reg_err = malloc(1024); regerror(ret_val, &re, reg_err, 1024); @@ -171,25 +169,24 @@ char *gadgets_retrieve_current_temperature(char *output, int max_len) return NULL; } regfree(&re); - char* ende; + char* ende = output; if (max_len > 0) { - int i = snprintf(output, max_len, "%.*s (%.*s %.*s-%.*s-%.*s)", - (int)(rm[6].rm_eo - rm[6].rm_so), (char*)(chunk.memory + rm[6].rm_so), - (int)(rm[4].rm_eo - rm[4].rm_so), (char*)(chunk.memory + rm[4].rm_so), - (int)(rm[3].rm_eo - rm[3].rm_so), (char*)(chunk.memory + rm[3].rm_so), - (int)(rm[2].rm_eo - rm[2].rm_so), (char*)(chunk.memory + rm[2].rm_so), - (int)(rm[1].rm_eo - rm[1].rm_so), (char*)(chunk.memory + rm[1].rm_so) + struct tm time_struct; + if (strptime((char*)(chunk.memory + rm[1].rm_so),"%d.%m.%Y um %H:%M MEZ",&time_struct) == NULL) { + fprintf(stderr, "Failed to parse time '%.*s'\n", (int)(rm[1].rm_eo - rm[1].rm_so), (char*)(chunk.memory + rm[1].rm_so)); + free(chunk.memory); + return NULL; + } + time_struct.tm_isdst = 0; // the fh gives CET all the time + mktime(&time_struct); + ende += snprintf(output, max_len, "%.*s", + (int)(rm[3].rm_eo - rm[3].rm_so), (char*)(chunk.memory + rm[3].rm_so) // temperature ); - ende = output + i; - for (; i>=0; i--) - if (output[i] == '(') - break; - for (; i>=0; i--) - if (output[i] == '.') - output[i] = ','; + for (char *i = output; i < ende; i++) + if (*i == '.') + *i = ','; + ende += strftime(ende, output + max_len - ende, " (%m-%d %H:%M)", &time_struct); } - else - ende = output; free(chunk.memory); return ende; } |