summaryrefslogtreecommitdiff
path: root/input_gadgets.c
diff options
context:
space:
mode:
authorErich Eckner <git@eckner.net>2019-09-23 21:48:29 +0200
committerErich Eckner <git@eckner.net>2019-09-23 21:48:29 +0200
commit973ea982a7c50a53b6437c54505164f73ccfcc96 (patch)
tree438246b7f1cc05b401e1961f49d1dd66b8e4b2cd /input_gadgets.c
parenta5a593c1b5cd60119f9b21c65640fffc0a765a0b (diff)
downloadanzeige-973ea982a7c50a53b6437c54505164f73ccfcc96.tar.xz
extract temperature and humidity binarily
Diffstat (limited to 'input_gadgets.c')
-rw-r--r--input_gadgets.c13
1 files changed, 9 insertions, 4 deletions
diff --git a/input_gadgets.c b/input_gadgets.c
index 907e05e..16a263d 100644
--- a/input_gadgets.c
+++ b/input_gadgets.c
@@ -12,7 +12,7 @@
#include "input_gadgets.h"
-#define fh_temperature_regex "\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 fh_temperature_regex "\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>(.|\n)*>Luftfeuchtigkeit</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)
@@ -138,7 +138,7 @@ size_t adaptive_strftime(char *s, size_t max, const struct tm *tm_print)
return strftime(s, max, "%H:%M", tm_print);
}
-char *gadgets_retrieve_current_temperature(char *output, int max_len)
+char *gadgets_retrieve_current_temperature(char *output, int max_len, double *temperature, double *humidity)
{
CURL *curl_handle;
CURLcode res;
@@ -180,13 +180,13 @@ char *gadgets_retrieve_current_temperature(char *output, int max_len)
}
regex_t re;
- regmatch_t rm[4];
+ regmatch_t rm[6];
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, 4, rm, 0)) {
+ if (ret_val = regexec(&re, chunk.memory, 6, rm, 0)) {
char *reg_err;
reg_err = malloc(1024);
regerror(ret_val, &re, reg_err, 1024);
@@ -210,6 +210,11 @@ char *gadgets_retrieve_current_temperature(char *output, int max_len)
ende += snprintf(output, max_len, "%.*s",
(int)(rm[3].rm_eo - rm[3].rm_so), (char*)(chunk.memory + rm[3].rm_so) // temperature
);
+ char tmp_str[7];
+ snprintf(tmp_str, 6, "%.*s", (int)(rm[3].rm_eo - rm[3].rm_so - 3), (char*)(chunk.memory + rm[3].rm_so));
+ *temperature = atof(tmp_str);
+ snprintf(tmp_str, 6, "%.*s", (int)(rm[5].rm_eo - rm[5].rm_so - 2), (char*)(chunk.memory + rm[5].rm_so));
+ *humidity = atof(tmp_str);
for (char *i = output; i < ende; i++)
if (*i == '.')
*i = ',';