mirror of
https://github.com/Llewellynvdm/conky.git
synced 2024-11-18 02:55:12 +00:00
Clarify weather opts, refactor some weather code.
This commit is contained in:
parent
f67ebec5e3
commit
9cda78c023
@ -354,27 +354,27 @@ dnl
|
|||||||
dnl WEATHER
|
dnl WEATHER
|
||||||
dnl
|
dnl
|
||||||
|
|
||||||
AC_ARG_ENABLE([weather],
|
AC_ARG_ENABLE([weather-metar],
|
||||||
AC_HELP_STRING([--enable-weather], [enable if you want weather support @<:@default=no@:>@]),
|
AC_HELP_STRING([--enable-weather-metar], [enable if you want METAR weather support @<:@default=no@:>@]),
|
||||||
[want_weather="$enableval"], [want_weather=no])
|
[want_metar="$enableval"], [want_metar=no])
|
||||||
|
|
||||||
AC_ARG_ENABLE([xoap],
|
AC_ARG_ENABLE([weather-xoap],
|
||||||
AC_HELP_STRING([--enable-xoap], [enable if you want weather xoap support @<:@default=no@:>@]),
|
AC_HELP_STRING([--enable-weather-xoap], [enable if you want XOAP weather support (also enables METAR) @<:@default=no@:>@]),
|
||||||
[want_xoap="$enableval"], [want_xoap=no])
|
[want_xoap="$enableval"], [want_xoap=no])
|
||||||
#
|
#
|
||||||
if test x$want_xoap = xyes; then
|
if test x$want_xoap = xyes; then
|
||||||
want_weather=yes
|
want_metar=yes
|
||||||
fi
|
fi
|
||||||
AM_CONDITIONAL(BUILD_WEATHER, test x$want_weather = xyes)
|
AM_CONDITIONAL(BUILD_WEATHER, test x$want_metar = xyes)
|
||||||
AM_CONDITIONAL(BUILD_XOAP, test x$want_xoap = xyes)
|
AM_CONDITIONAL(BUILD_XOAP, test x$want_xoap = xyes)
|
||||||
if test x$want_weather = xyes; then
|
if test x$want_metar = xyes; then
|
||||||
if test x$want_xoap = xyes; then
|
if test x$want_xoap = xyes; then
|
||||||
want_libxml2=yes
|
want_libxml2=yes
|
||||||
AC_DEFINE(XOAP, 1, [Define if you want weather xoap support])
|
AC_DEFINE(XOAP, 1, [Define if you want XOAP weather support])
|
||||||
AC_DEFINE(XOAP_FILE, "$HOME/.xoaprc", [User xoap keys file])
|
AC_DEFINE(XOAP_FILE, "$HOME/.xoaprc", [User xoap keys file])
|
||||||
fi
|
fi
|
||||||
want_curl=yes
|
want_curl=yes
|
||||||
AC_DEFINE(WEATHER, 1, [Define if you want weather support])
|
AC_DEFINE(WEATHER, 1, [Define if you want METAR weather support])
|
||||||
fi
|
fi
|
||||||
|
|
||||||
dnl
|
dnl
|
||||||
@ -934,7 +934,7 @@ $PACKAGE $VERSION configured successfully:
|
|||||||
RSS: $want_rss
|
RSS: $want_rss
|
||||||
Curl: $want_curl
|
Curl: $want_curl
|
||||||
Weather
|
Weather
|
||||||
NOAA: $want_weather
|
METAR: $want_metar
|
||||||
XOAP: $want_xoap
|
XOAP: $want_xoap
|
||||||
wireless: $want_wlan
|
wireless: $want_wlan
|
||||||
IBM: $want_ibm
|
IBM: $want_ibm
|
||||||
|
75
src/conky.c
75
src/conky.c
@ -216,7 +216,7 @@ static void print_version(void)
|
|||||||
" * RSS\n"
|
" * RSS\n"
|
||||||
#endif /* RSS */
|
#endif /* RSS */
|
||||||
#ifdef WEATHER
|
#ifdef WEATHER
|
||||||
" * Weather (NOAA)\n"
|
" * Weather (METAR)\n"
|
||||||
#ifdef XOAP
|
#ifdef XOAP
|
||||||
" * Weather (XOAP)\n"
|
" * Weather (XOAP)\n"
|
||||||
#endif /* XOAP */
|
#endif /* XOAP */
|
||||||
@ -325,11 +325,6 @@ static int cpu_avg_samples, net_avg_samples, diskio_avg_samples;
|
|||||||
char *overwrite_file = NULL; FILE *overwrite_fpointer = NULL;
|
char *overwrite_file = NULL; FILE *overwrite_fpointer = NULL;
|
||||||
char *append_file = NULL; FILE *append_fpointer = NULL;
|
char *append_file = NULL; FILE *append_fpointer = NULL;
|
||||||
|
|
||||||
/* xoap suffix for weather from weather.com */
|
|
||||||
#ifdef WEATHER
|
|
||||||
static char *xoap = NULL;
|
|
||||||
#endif /* WEATHER */
|
|
||||||
|
|
||||||
#ifdef X11
|
#ifdef X11
|
||||||
|
|
||||||
static int show_graph_scale;
|
static int show_graph_scale;
|
||||||
@ -2829,7 +2824,7 @@ static struct text_object *construct_text_object(const char *s,
|
|||||||
END OBJ(curl, 0)
|
END OBJ(curl, 0)
|
||||||
if (arg) {
|
if (arg) {
|
||||||
int argc;
|
int argc;
|
||||||
float interval;
|
float interval = 0;
|
||||||
char *uri = (char *) malloc(128 * sizeof(char));
|
char *uri = (char *) malloc(128 * sizeof(char));
|
||||||
|
|
||||||
argc = sscanf(arg, "%127s %f", uri, &interval);
|
argc = sscanf(arg, "%127s %f", uri, &interval);
|
||||||
@ -2846,7 +2841,7 @@ static struct text_object *construct_text_object(const char *s,
|
|||||||
#ifdef RSS
|
#ifdef RSS
|
||||||
END OBJ(rss, 0)
|
END OBJ(rss, 0)
|
||||||
if (arg) {
|
if (arg) {
|
||||||
float interval;
|
float interval = 0;
|
||||||
int argc, act_par;
|
int argc, act_par;
|
||||||
unsigned int nrspaces = 0;
|
unsigned int nrspaces = 0;
|
||||||
char *uri = (char *) malloc(128 * sizeof(char));
|
char *uri = (char *) malloc(128 * sizeof(char));
|
||||||
@ -2872,35 +2867,15 @@ static struct text_object *construct_text_object(const char *s,
|
|||||||
END OBJ(weather, 0)
|
END OBJ(weather, 0)
|
||||||
if (arg) {
|
if (arg) {
|
||||||
int argc;
|
int argc;
|
||||||
float interval;
|
float interval = 0;
|
||||||
char *locID = (char *) malloc(9 * sizeof(char));
|
char *locID = (char *) malloc(9 * sizeof(char));
|
||||||
char *uri = (char *) malloc(128 * sizeof(char));
|
char *uri = (char *) malloc(128 * sizeof(char));
|
||||||
char *data_type = (char *) malloc(32 * sizeof(char));
|
char *data_type = (char *) malloc(32 * sizeof(char));
|
||||||
char *tmp_p;
|
|
||||||
|
|
||||||
argc = sscanf(arg, "%119s %8s %31s %f", uri, locID, data_type, &interval);
|
argc = sscanf(arg, "%119s %8s %31s %f", uri, locID, data_type, &interval);
|
||||||
|
|
||||||
if (argc >= 3) {
|
if (argc >= 3) {
|
||||||
/* locID MUST BE upper-case */
|
if (process_weather_uri(uri, locID)) {
|
||||||
tmp_p = locID;
|
|
||||||
while (*tmp_p) {
|
|
||||||
*tmp_p = toupper(*tmp_p);
|
|
||||||
tmp_p++;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Construct complete uri */
|
|
||||||
if (strstr(uri, "xoap.weather.com")) {
|
|
||||||
if(xoap != NULL) {
|
|
||||||
strcat(uri, locID);
|
|
||||||
strcat(uri, xoap);
|
|
||||||
} else {
|
|
||||||
free(uri);
|
|
||||||
uri = NULL;
|
|
||||||
}
|
|
||||||
} else if (strstr(uri, "weather.noaa.gov")) {
|
|
||||||
strcat(uri, locID);
|
|
||||||
strcat(uri, ".TXT");
|
|
||||||
} else if (!strstr(uri, "localhost") && !strstr(uri, "127.0.0.1")) {
|
|
||||||
CRIT_ERR(obj, free_at_crash, \
|
CRIT_ERR(obj, free_at_crash, \
|
||||||
"could not recognize the weather uri");
|
"could not recognize the weather uri");
|
||||||
}
|
}
|
||||||
@ -9008,42 +8983,6 @@ static void load_config_file_x11(const char *f)
|
|||||||
}
|
}
|
||||||
#endif /* X11 */
|
#endif /* X11 */
|
||||||
|
|
||||||
#if defined(WEATHER) && defined(XOAP)
|
|
||||||
/*
|
|
||||||
* TODO: make the xoap keys file readable from the config file
|
|
||||||
* make the keys directly readable from the config file
|
|
||||||
* make the xoap keys file giveable as a command line option
|
|
||||||
*/
|
|
||||||
static void load_xoap_keys(void)
|
|
||||||
{
|
|
||||||
FILE *fp;
|
|
||||||
char *par = (char *) malloc(11 * sizeof(char));
|
|
||||||
char *key = (char *) malloc(17 * sizeof(char));
|
|
||||||
|
|
||||||
xoap = (char *) malloc(64 * sizeof(char));
|
|
||||||
to_real_path(xoap, XOAP_FILE);
|
|
||||||
fp = fopen(xoap, "r");
|
|
||||||
if (fp != NULL) {
|
|
||||||
if( fscanf(fp, "%10s %16s", par, key) == 2 ) {
|
|
||||||
strcpy(xoap, "?cc=*&link=xoap&prod=xoap&par=");
|
|
||||||
strcat(xoap, par);
|
|
||||||
strcat(xoap, "&key=");
|
|
||||||
strcat(xoap, key);
|
|
||||||
strcat(xoap, "&unit=m");
|
|
||||||
} else {
|
|
||||||
free(xoap);
|
|
||||||
xoap = NULL;
|
|
||||||
}
|
|
||||||
fclose(fp);
|
|
||||||
} else {
|
|
||||||
free(xoap);
|
|
||||||
xoap = NULL;
|
|
||||||
}
|
|
||||||
free(par);
|
|
||||||
free(key);
|
|
||||||
}
|
|
||||||
#endif /* WEATHER && XOAP */
|
|
||||||
|
|
||||||
static void print_help(const char *prog_name) {
|
static void print_help(const char *prog_name) {
|
||||||
printf("Usage: %s [OPTION]...\n"
|
printf("Usage: %s [OPTION]...\n"
|
||||||
PACKAGE_NAME" is a system monitor that renders text on desktop or to own transparent\n"
|
PACKAGE_NAME" is a system monitor that renders text on desktop or to own transparent\n"
|
||||||
@ -9428,10 +9367,10 @@ int main(int argc, char **argv)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined(WEATHER) && defined(XOAP)
|
#ifdef XOAP
|
||||||
/* Load xoap keys, if existing */
|
/* Load xoap keys, if existing */
|
||||||
load_xoap_keys();
|
load_xoap_keys();
|
||||||
#endif /* WEATHER && XOAP */
|
#endif /* XOAP */
|
||||||
|
|
||||||
#ifdef HAVE_SYS_INOTIFY_H
|
#ifdef HAVE_SYS_INOTIFY_H
|
||||||
inotify_fd = inotify_init();
|
inotify_fd = inotify_init();
|
||||||
|
@ -95,6 +95,12 @@ char *strndup(const char *s, size_t n);
|
|||||||
#include "rss.h"
|
#include "rss.h"
|
||||||
#endif /* RSS */
|
#endif /* RSS */
|
||||||
|
|
||||||
|
#ifdef XOAP
|
||||||
|
#ifndef WEATHER
|
||||||
|
#error "WEATHER needs to be defined if XOAP is defined"
|
||||||
|
#endif /* WEATHER */
|
||||||
|
#endif /* XOAP */
|
||||||
|
|
||||||
#ifdef WEATHER
|
#ifdef WEATHER
|
||||||
#include "weather.h"
|
#include "weather.h"
|
||||||
#endif /* WEATHER */
|
#endif /* WEATHER */
|
||||||
|
@ -583,3 +583,73 @@ void weather_process_info(char *p, int p_max_size, char *uri, char *data_type, i
|
|||||||
timed_thread_unlock(curloc->p_timed_thread);
|
timed_thread_unlock(curloc->p_timed_thread);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef XOAP
|
||||||
|
|
||||||
|
/* xoap suffix for weather from weather.com */
|
||||||
|
static char *xoap = NULL;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* TODO: make the xoap keys file readable from the config file
|
||||||
|
* make the keys directly readable from the config file
|
||||||
|
* make the xoap keys file giveable as a command line option
|
||||||
|
*/
|
||||||
|
void load_xoap_keys(void)
|
||||||
|
{
|
||||||
|
FILE *fp;
|
||||||
|
char *par = (char *) malloc(11 * sizeof(char));
|
||||||
|
char *key = (char *) malloc(17 * sizeof(char));
|
||||||
|
|
||||||
|
xoap = (char *) malloc(64 * sizeof(char));
|
||||||
|
to_real_path(xoap, XOAP_FILE);
|
||||||
|
fp = fopen(xoap, "r");
|
||||||
|
if (fp != NULL) {
|
||||||
|
if (fscanf(fp, "%10s %16s", par, key) == 2) {
|
||||||
|
strcpy(xoap, "?cc=*&link=xoap&prod=xoap&par=");
|
||||||
|
strcat(xoap, par);
|
||||||
|
strcat(xoap, "&key=");
|
||||||
|
strcat(xoap, key);
|
||||||
|
strcat(xoap, "&unit=m");
|
||||||
|
} else {
|
||||||
|
free(xoap);
|
||||||
|
xoap = NULL;
|
||||||
|
}
|
||||||
|
fclose(fp);
|
||||||
|
} else {
|
||||||
|
free(xoap);
|
||||||
|
xoap = NULL;
|
||||||
|
}
|
||||||
|
free(par);
|
||||||
|
free(key);
|
||||||
|
}
|
||||||
|
#endif /* XOAP */
|
||||||
|
|
||||||
|
int process_weather_uri(char *uri, char *locID)
|
||||||
|
{
|
||||||
|
/* locID MUST BE upper-case */
|
||||||
|
char *tmp_p = locID;
|
||||||
|
while (*tmp_p) {
|
||||||
|
*tmp_p = toupper(*tmp_p);
|
||||||
|
tmp_p++;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Construct complete uri */
|
||||||
|
#ifdef XOAP
|
||||||
|
if (strstr(uri, "xoap.weather.com")) {
|
||||||
|
if (xoap != NULL) {
|
||||||
|
strcat(uri, locID);
|
||||||
|
strcat(uri, xoap);
|
||||||
|
} else {
|
||||||
|
free(uri);
|
||||||
|
uri = NULL;
|
||||||
|
}
|
||||||
|
} else
|
||||||
|
#endif /* XOAP */
|
||||||
|
if (strstr(uri, "weather.noaa.gov")) {
|
||||||
|
strcat(uri, locID);
|
||||||
|
strcat(uri, ".TXT");
|
||||||
|
} else if (!strstr(uri, "localhost") && !strstr(uri, "127.0.0.1")) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@ -28,6 +28,8 @@
|
|||||||
#ifndef WEATHER_H_
|
#ifndef WEATHER_H_
|
||||||
#define WEATHER_H_
|
#define WEATHER_H_
|
||||||
|
|
||||||
|
#include "config.h"
|
||||||
|
|
||||||
/* WEATHER data */
|
/* WEATHER data */
|
||||||
typedef struct PWEATHER_ {
|
typedef struct PWEATHER_ {
|
||||||
char lastupd[32];
|
char lastupd[32];
|
||||||
@ -57,5 +59,11 @@ typedef struct PWEATHER_ {
|
|||||||
/* Prototypes */
|
/* Prototypes */
|
||||||
void weather_free_info(void);
|
void weather_free_info(void);
|
||||||
void weather_process_info(char *p, int p_max_size, char *uri, char *data_type, int interval);
|
void weather_process_info(char *p, int p_max_size, char *uri, char *data_type, int interval);
|
||||||
|
int process_weather_uri(char *uri, char *locID);
|
||||||
|
|
||||||
|
#ifdef XOAP
|
||||||
|
void load_xoap_keys(void);
|
||||||
|
#endif /* XOAP */
|
||||||
|
|
||||||
|
|
||||||
#endif /*WEATHER_H_*/
|
#endif /*WEATHER_H_*/
|
||||||
|
Loading…
Reference in New Issue
Block a user