summaryrefslogtreecommitdiff
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
parenta5a593c1b5cd60119f9b21c65640fffc0a765a0b (diff)
downloadanzeige-973ea982a7c50a53b6437c54505164f73ccfcc96.tar.xz
extract temperature and humidity binarily
-rw-r--r--anzeige.c4
-rw-r--r--input_gadgets.c13
-rw-r--r--input_gadgets.h2
3 files changed, 13 insertions, 6 deletions
diff --git a/anzeige.c b/anzeige.c
index 2a28867..67a2046 100644
--- a/anzeige.c
+++ b/anzeige.c
@@ -85,6 +85,8 @@ int main(int argc, char **argv)
text_buffer_end = text_buffer;
+ double temperature, humidity;
+
text_buffer_end = gadgets_retrieve_weather_warnings(text_buffer_end,text_buffer + TEXT_BUFFER_LENGTH - text_buffer_end);
if (text_buffer_end == NULL) {
fprintf(stderr, "gadgets_retrieve_weather_warnings failed\n");
@@ -94,7 +96,7 @@ int main(int argc, char **argv)
}
if (text_buffer + TEXT_BUFFER_LENGTH - text_buffer_end > 0)
text_buffer_end += snprintf(text_buffer_end, text_buffer + TEXT_BUFFER_LENGTH - text_buffer_end, "; ");
- text_buffer_end = gadgets_retrieve_current_temperature(text_buffer_end,text_buffer + TEXT_BUFFER_LENGTH - text_buffer_end);
+ text_buffer_end = gadgets_retrieve_current_temperature(text_buffer_end, text_buffer + TEXT_BUFFER_LENGTH - text_buffer_end, &temperature, &humidity);
if (text_buffer_end == NULL) {
fprintf(stderr, "gadgets_retrieve_current_temperature failed\n");
free(text_buffer);
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 = ',';
diff --git a/input_gadgets.h b/input_gadgets.h
index 1c667e3..eee6915 100644
--- a/input_gadgets.h
+++ b/input_gadgets.h
@@ -15,7 +15,7 @@ typedef struct {
time_t onset, expires;
} warning_t;
-char *gadgets_retrieve_current_temperature(char *output, int max_len);
+char *gadgets_retrieve_current_temperature(char *output, int max_len, double *temperature, double *humidity);
char *gadgets_retrieve_weather_forecast(char *output, int max_len);
char *gadgets_retrieve_weather_warnings(char *output, int max_len);