mirror of
https://github.com/Llewellynvdm/conky.git
synced 2025-01-12 19:06:36 +00:00
Added support for $weather (experimental).
Download, parse and display METAR data from the NWS. icao must be a valid icao for the required location (see for instance https://pilotweb.nas.faa.gov/qryhtml/icao/). data_type must be one of the following: last_update : display the date (yyyy/mm/dd) and time (UTC) of the last update. temperature_C : display air temperature in degree Celsius. temperature_F : display air temperature in degree Fahrenheit. cloud_cover : display the highest cloud cover status. pressure : display air pressure in millibar. wind_speed : display wind speed in km/hour. wind_dir : display wind direction. wind_dir_DEG : display compass wind direction. humidity : display relative humidity in %. weather : display any relevant weather event (rain, snow, etc.). delay_in_minutes (optional, default 30) cannot be lower than 30 min. Up to 3 stations can be simultaneously queried. Use --enable-weather to compile this in.
This commit is contained in:
parent
ae6c02b0c8
commit
1171ab38a5
@ -1,3 +1,6 @@
|
||||
2009-07-06
|
||||
* Added support for $weather (experimental)
|
||||
|
||||
2009-07-04
|
||||
* Remove newline with comment only lines in TEXT
|
||||
* Improved parsing of graph arguments, removed "log"|"normal" arguments in
|
||||
|
@ -343,6 +343,23 @@ if test x$want_rss = xyes; then
|
||||
AC_DEFINE(RSS, 1, [Define if you want rss support])
|
||||
fi
|
||||
|
||||
dnl
|
||||
dnl WEATHER
|
||||
dnl
|
||||
|
||||
AC_ARG_ENABLE([weather],
|
||||
AC_HELP_STRING([--enable-weather], [enable if you want weather support @<:@default=no@:>@]),
|
||||
[want_weather="$enableval"], [want_weather=no])
|
||||
#
|
||||
AM_CONDITIONAL(BUILD_WEATHER, test x$want_weather = xyes)
|
||||
if test x$want_weather = xyes; then
|
||||
WANT_GLIB=yes
|
||||
PKG_CHECK_MODULES([libcurl], libcurl)
|
||||
CFLAGS="$CFLAGS $libcurl_CFLAGS"
|
||||
LIBS="$LIBS $libcurl_LIBS"
|
||||
AC_DEFINE(WEATHER, 1, [Define if you want weather support])
|
||||
fi
|
||||
|
||||
dnl
|
||||
dnl Lua
|
||||
dnl
|
||||
@ -833,6 +850,7 @@ $PACKAGE $VERSION configured successfully:
|
||||
hddtemp: $want_hddtemp
|
||||
portmon: $want_portmon
|
||||
RSS: $want_rss
|
||||
WEATHER: $want_weather
|
||||
Lua: $want_lua
|
||||
wireless: $want_wlan
|
||||
IBM: $want_ibm
|
||||
|
@ -3198,6 +3198,31 @@
|
||||
from 1. If omitted, the parameter defaults to 1.
|
||||
<para /></listitem>
|
||||
</varlistentry>
|
||||
<varlistentry>
|
||||
<term>
|
||||
<command>
|
||||
<option>weather</option>
|
||||
</command>
|
||||
<option>icao data_type (delay_in_minutes)</option>
|
||||
</term>
|
||||
<listitem>Download, parse and display METAR data from the
|
||||
NWS. icao must be a valid icao for the required location
|
||||
(see for instance https://pilotweb.nas.faa.gov/qryhtml/icao/).
|
||||
data_type must be one of the following: last_update
|
||||
(display the date (yyyy/mm/dd) and time (UTC) of the last
|
||||
update), temperature_C (display air temperature in degree
|
||||
Celsius), temperature_F (display air temperature in degree
|
||||
Fahrenheit), cloud_cover (display the highest cloud cover
|
||||
status), pressure (display air pressure in millibar),
|
||||
wind_speed (display wind speed in km/hour), wind_dir (display
|
||||
wind direction), wind_dir_DEG (display compass wind direction),
|
||||
humidity (display relative humidity in %), weather (display
|
||||
any relevant weather event (rain, snow, etc.)).
|
||||
delay_in_minutes (optional, default 30) cannot be lower than
|
||||
30 min. Up to 3 stations can be simultaneously queried. Note
|
||||
that this feature is still EXPERIMENTAL.
|
||||
<para /></listitem>
|
||||
</varlistentry>
|
||||
<varlistentry>
|
||||
<term>
|
||||
<command>
|
||||
|
@ -11,7 +11,7 @@ color green "\<(alias|alignment|append_file|background|border_inner_margin|borde
|
||||
color yellow "\<(above|below|bottom_left|bottom_right|bottom_middle|desktop|dock|no|none|normal|override|skip_pager|skip_taskbar|sticky|top_left|top_right|top_middle|middle_left|middle_right|undecorated|yes)\>"
|
||||
|
||||
## Variables
|
||||
color brightblue "\<(acpiacadapter|acpifan|acpitemp|addr|addrs|adt746xcpu|adt746xfan|alignc|alignr|apcupsd|apcupsd_cable|apcupsd_charge|apcupsd_lastxfer|apcupsd_linev|apcupsd_load|apcupsd_loadbar|apcupsd_loadgauge|apcupsd_loadgraph|apcupsd_model|apcupsd_name|apcupsd_status|apcupsd_temp|apcupsd_timeleft|apcupsd_upsmode|apm_adapter|apm_battery_life|apm_battery_time|audacious_bar|audacious_bitrate|audacious_channels|audacious_filename|audacious_frequency|audacious_length|audacious_length_seconds|audacious_main_volume|audacious_playlist_length|audacious_playlist_position|audacious_position|audacious_position_seconds|audacious_status|audacious_title|battery|battery_bar|battery_percent|battery_short|battery_time|blink|bmpx_album|bmpx_artist|bmpx_bitrate|bmpx_title|bmpx_track|bmpx_uri|buffers|cached|color|color0|color1|color2|color3|color4|color5|color6|color7|color8|color9|combine|conky_build_arch|conky_build_date|conky_version|cpu|cpubar|cpugauge|cpugraph|disk_protect|diskio|diskio_read|diskio_write|diskiograph|diskiograph_read|diskiograph_write|downspeed|downspeedf|downspeedgraph|draft_mails|else|endif|entropy_avail|entropy_bar|entropy_perc|entropy_poolsize|eval|eve|exec|execbar|execgauge|execgraph|execi|execibar|execigauge|execigraph|execp|execpi|flagged_mails|font|forwarded_mails|freq|freq_g|fs_bar|fs_bar_free|fs_free|fs_free_perc|fs_size|fs_type|fs_used|fs_used_perc|goto|gw_iface|gw_ip|hddtemp|head|hr|hwmon|i2c|i8k_ac_status|i8k_bios|i8k_buttons_status|i8k_cpu_temp|i8k_left_fan_rpm|i8k_left_fan_status|i8k_right_fan_rpm|i8k_right_fan_status|i8k_serial|i8k_version|ibm_brightness|ibm_fan|ibm_temps|ibm_volume|iconv_start|iconv_stop|if_empty|if_existing|if_gw|if_match|if_mixer_mute|if_mounted|if_mpd_playing|if_running|if_smapi_bat_installed|if_up|if_updatenr|if_xmms2_connected|image|imap_messages|imap_unseen|ioscheduler|kernel|laptop_mode|lines|loadavg|loadgraph|lua|lua_bar|lua_gauge|lua_graph|lua_parse|lua_read_parse|machine|mails|mboxscan|mem|membar|memeasyfree|memfree|memgauge|memgraph|memmax|memperc|mixer|mixerbar|mixerl|mixerlbar|mixerr|mixerrbar|moc_album|moc_artist|moc_bitrate|moc_curtime|moc_file|moc_rate|moc_song|moc_state|moc_timeleft|moc_title|moc_totaltime|monitor|monitor_number|mpd_album|mpd_artist|mpd_bar|mpd_bitrate|mpd_elapsed|mpd_file|mpd_length|mpd_name|mpd_percent|mpd_random|mpd_repeat|mpd_smart|mpd_status|mpd_title|mpd_track|mpd_vol|nameserver|new_mails|nodename|nvidia|obsd_product|obsd_sensors_fan|obsd_sensors_temp|obsd_sensors_volt|obsd_vendor|offset|outlinecolor|pb_battery|platform|pop3_unseen|pop3_used|pre_exec|processes|read_tcp|replied_mails|rss|running_processes|scroll|seen_mails|shadecolor|smapi|smapi_bat_bar|smapi_bat_perc|smapi_bat_power|smapi_bat_temp|sony_fanspeed|stippled_hr|swap|swapbar|swapmax|swapperc|sysname|tab|tail|tcp_portmon|template0|template1|template2|template3|template4|template5|template6|template7|template8|template9|texeci|time|to_bytes|top|top_io|top_mem|top_time|totaldown|totalup|trashed_mails|tztime|unflagged_mails|unforwarded_mails|unreplied_mails|unseen_mails|updates|upspeed|upspeedf|upspeedgraph|uptime|uptime_short|user_names|user_number|user_terms|user_times|utime|voffset|voltage_mv|voltage_v|wireless_ap|wireless_bitrate|wireless_essid|wireless_link_bar|wireless_link_qual|wireless_link_qual_max|wireless_link_qual_perc|wireless_mode|words|xmms2_album|xmms2_artist|xmms2_bar|xmms2_bitrate|xmms2_comment|xmms2_date|xmms2_duration|xmms2_elapsed|xmms2_genre|xmms2_id|xmms2_percent|xmms2_playlist|xmms2_size|xmms2_smart|xmms2_status|xmms2_timesplayed|xmms2_title|xmms2_tracknr|xmms2_url)\>"
|
||||
color brightblue "\<(acpiacadapter|acpifan|acpitemp|addr|addrs|adt746xcpu|adt746xfan|alignc|alignr|apcupsd|apcupsd_cable|apcupsd_charge|apcupsd_lastxfer|apcupsd_linev|apcupsd_load|apcupsd_loadbar|apcupsd_loadgauge|apcupsd_loadgraph|apcupsd_model|apcupsd_name|apcupsd_status|apcupsd_temp|apcupsd_timeleft|apcupsd_upsmode|apm_adapter|apm_battery_life|apm_battery_time|audacious_bar|audacious_bitrate|audacious_channels|audacious_filename|audacious_frequency|audacious_length|audacious_length_seconds|audacious_main_volume|audacious_playlist_length|audacious_playlist_position|audacious_position|audacious_position_seconds|audacious_status|audacious_title|battery|battery_bar|battery_percent|battery_short|battery_time|blink|bmpx_album|bmpx_artist|bmpx_bitrate|bmpx_title|bmpx_track|bmpx_uri|buffers|cached|color|color0|color1|color2|color3|color4|color5|color6|color7|color8|color9|combine|conky_build_arch|conky_build_date|conky_version|cpu|cpubar|cpugauge|cpugraph|disk_protect|diskio|diskio_read|diskio_write|diskiograph|diskiograph_read|diskiograph_write|downspeed|downspeedf|downspeedgraph|draft_mails|else|endif|entropy_avail|entropy_bar|entropy_perc|entropy_poolsize|eval|eve|exec|execbar|execgauge|execgraph|execi|execibar|execigauge|execigraph|execp|execpi|flagged_mails|font|forwarded_mails|freq|freq_g|fs_bar|fs_bar_free|fs_free|fs_free_perc|fs_size|fs_type|fs_used|fs_used_perc|goto|gw_iface|gw_ip|hddtemp|head|hr|hwmon|i2c|i8k_ac_status|i8k_bios|i8k_buttons_status|i8k_cpu_temp|i8k_left_fan_rpm|i8k_left_fan_status|i8k_right_fan_rpm|i8k_right_fan_status|i8k_serial|i8k_version|ibm_brightness|ibm_fan|ibm_temps|ibm_volume|iconv_start|iconv_stop|if_empty|if_existing|if_gw|if_match|if_mixer_mute|if_mounted|if_mpd_playing|if_running|if_smapi_bat_installed|if_up|if_updatenr|if_xmms2_connected|image|imap_messages|imap_unseen|ioscheduler|kernel|laptop_mode|lines|loadavg|loadgraph|lua|lua_bar|lua_gauge|lua_graph|lua_parse|lua_read_parse|machine|mails|mboxscan|mem|membar|memeasyfree|memfree|memgauge|memgraph|memmax|memperc|mixer|mixerbar|mixerl|mixerlbar|mixerr|mixerrbar|moc_album|moc_artist|moc_bitrate|moc_curtime|moc_file|moc_rate|moc_song|moc_state|moc_timeleft|moc_title|moc_totaltime|monitor|monitor_number|mpd_album|mpd_artist|mpd_bar|mpd_bitrate|mpd_elapsed|mpd_file|mpd_length|mpd_name|mpd_percent|mpd_random|mpd_repeat|mpd_smart|mpd_status|mpd_title|mpd_track|mpd_vol|nameserver|new_mails|nodename|nvidia|obsd_product|obsd_sensors_fan|obsd_sensors_temp|obsd_sensors_volt|obsd_vendor|offset|outlinecolor|pb_battery|platform|pop3_unseen|pop3_used|pre_exec|processes|read_tcp|replied_mails|rss|running_processes|scroll|seen_mails|shadecolor|smapi|smapi_bat_bar|smapi_bat_perc|smapi_bat_power|smapi_bat_temp|sony_fanspeed|stippled_hr|swap|swapbar|swapmax|swapperc|sysname|tab|tail|tcp_portmon|template0|template1|template2|template3|template4|template5|template6|template7|template8|template9|texeci|time|to_bytes|top|top_io|top_mem|top_time|totaldown|totalup|trashed_mails|tztime|unflagged_mails|unforwarded_mails|unreplied_mails|unseen_mails|updates|upspeed|upspeedf|upspeedgraph|uptime|uptime_short|user_names|user_number|user_terms|user_times|utime|voffset|voltage_mv|voltage_v|weather|wireless_ap|wireless_bitrate|wireless_essid|wireless_link_bar|wireless_link_qual|wireless_link_qual_max|wireless_link_qual_perc|wireless_mode|words|xmms2_album|xmms2_artist|xmms2_bar|xmms2_bitrate|xmms2_comment|xmms2_date|xmms2_duration|xmms2_elapsed|xmms2_genre|xmms2_id|xmms2_percent|xmms2_playlist|xmms2_size|xmms2_smart|xmms2_status|xmms2_timesplayed|xmms2_title|xmms2_tracknr|xmms2_url)\>"
|
||||
|
||||
color brightblue "\$\{?[0-9A-Z_!@#$*?-]+\}?"
|
||||
color cyan "(\{|\}|\(|\)|\;|\]|\[|`|\\|\$|<|>|!|=|&|\|)"
|
||||
|
@ -49,7 +49,7 @@ syn region ConkyrcVar start=/\$\w\@=/ end=/\W\@=\|$/ contained contains=ConkyrcV
|
||||
|
||||
syn match ConkyrcVarStuff /{\@<=/ms=s contained nextgroup=ConkyrcVarName
|
||||
|
||||
syn keyword ConkyrcVarName contained nextgroup=ConkyrcNumber,ConkyrcColour skipwhite acpiacadapter acpifan acpitemp addr addrs adt746xcpu adt746xfan alignc alignr apcupsd apcupsd_cable apcupsd_charge apcupsd_lastxfer apcupsd_linev apcupsd_load apcupsd_loadbar apcupsd_loadgauge apcupsd_loadgraph apcupsd_model apcupsd_name apcupsd_status apcupsd_temp apcupsd_timeleft apcupsd_upsmode apm_adapter apm_battery_life apm_battery_time audacious_bar audacious_bitrate audacious_channels audacious_filename audacious_frequency audacious_length audacious_length_seconds audacious_main_volume audacious_playlist_length audacious_playlist_position audacious_position audacious_position_seconds audacious_status audacious_title battery battery_bar battery_percent battery_short battery_time blink bmpx_album bmpx_artist bmpx_bitrate bmpx_title bmpx_track bmpx_uri buffers cached color color0 color1 color2 color3 color4 color5 color6 color7 color8 color9 combine conky_build_arch conky_build_date conky_version cpu cpubar cpugauge cpugraph disk_protect diskio diskio_read diskio_write diskiograph diskiograph_read diskiograph_write downspeed downspeedf downspeedgraph draft_mails else endif entropy_avail entropy_bar entropy_perc entropy_poolsize eval eve exec execbar execgauge execgraph execi execibar execigauge execigraph execp execpi flagged_mails font forwarded_mails freq freq_g fs_bar fs_bar_free fs_free fs_free_perc fs_size fs_type fs_used fs_used_perc goto gw_iface gw_ip hddtemp head hr hwmon i2c i8k_ac_status i8k_bios i8k_buttons_status i8k_cpu_temp i8k_left_fan_rpm i8k_left_fan_status i8k_right_fan_rpm i8k_right_fan_status i8k_serial i8k_version ibm_brightness ibm_fan ibm_temps ibm_volume iconv_start iconv_stop if_empty if_existing if_gw if_match if_mixer_mute if_mounted if_mpd_playing if_running if_smapi_bat_installed if_up if_updatenr if_xmms2_connected image imap_messages imap_unseen ioscheduler kernel laptop_mode lines loadavg loadgraph lua lua_bar lua_gauge lua_graph lua_parse lua_read_parse machine mails mboxscan mem membar memeasyfree memfree memgauge memgraph memmax memperc mixer mixerbar mixerl mixerlbar mixerr mixerrbar moc_album moc_artist moc_bitrate moc_curtime moc_file moc_rate moc_song moc_state moc_timeleft moc_title moc_totaltime monitor monitor_number mpd_album mpd_artist mpd_bar mpd_bitrate mpd_elapsed mpd_file mpd_length mpd_name mpd_percent mpd_random mpd_repeat mpd_smart mpd_status mpd_title mpd_track mpd_vol nameserver new_mails nodename nvidia obsd_product obsd_sensors_fan obsd_sensors_temp obsd_sensors_volt obsd_vendor offset outlinecolor pb_battery platform pop3_unseen pop3_used pre_exec processes read_tcp replied_mails rss running_processes scroll seen_mails shadecolor smapi smapi_bat_bar smapi_bat_perc smapi_bat_power smapi_bat_temp sony_fanspeed stippled_hr swap swapbar swapmax swapperc sysname tab tail tcp_portmon template0 template1 template2 template3 template4 template5 template6 template7 template8 template9 texeci time to_bytes top top_io top_mem top_time totaldown totalup trashed_mails tztime unflagged_mails unforwarded_mails unreplied_mails unseen_mails updates upspeed upspeedf upspeedgraph uptime uptime_short user_names user_number user_terms user_times utime voffset voltage_mv voltage_v wireless_ap wireless_bitrate wireless_essid wireless_link_bar wireless_link_qual wireless_link_qual_max wireless_link_qual_perc wireless_mode words xmms2_album xmms2_artist xmms2_bar xmms2_bitrate xmms2_comment xmms2_date xmms2_duration xmms2_elapsed xmms2_genre xmms2_id xmms2_percent xmms2_playlist xmms2_size xmms2_smart xmms2_status xmms2_timesplayed xmms2_title xmms2_tracknr xmms2_url
|
||||
syn keyword ConkyrcVarName contained nextgroup=ConkyrcNumber,ConkyrcColour skipwhite acpiacadapter acpifan acpitemp addr addrs adt746xcpu adt746xfan alignc alignr apcupsd apcupsd_cable apcupsd_charge apcupsd_lastxfer apcupsd_linev apcupsd_load apcupsd_loadbar apcupsd_loadgauge apcupsd_loadgraph apcupsd_model apcupsd_name apcupsd_status apcupsd_temp apcupsd_timeleft apcupsd_upsmode apm_adapter apm_battery_life apm_battery_time audacious_bar audacious_bitrate audacious_channels audacious_filename audacious_frequency audacious_length audacious_length_seconds audacious_main_volume audacious_playlist_length audacious_playlist_position audacious_position audacious_position_seconds audacious_status audacious_title battery battery_bar battery_percent battery_short battery_time blink bmpx_album bmpx_artist bmpx_bitrate bmpx_title bmpx_track bmpx_uri buffers cached color color0 color1 color2 color3 color4 color5 color6 color7 color8 color9 combine conky_build_arch conky_build_date conky_version cpu cpubar cpugauge cpugraph disk_protect diskio diskio_read diskio_write diskiograph diskiograph_read diskiograph_write downspeed downspeedf downspeedgraph draft_mails else endif entropy_avail entropy_bar entropy_perc entropy_poolsize eval eve exec execbar execgauge execgraph execi execibar execigauge execigraph execp execpi flagged_mails font forwarded_mails freq freq_g fs_bar fs_bar_free fs_free fs_free_perc fs_size fs_type fs_used fs_used_perc goto gw_iface gw_ip hddtemp head hr hwmon i2c i8k_ac_status i8k_bios i8k_buttons_status i8k_cpu_temp i8k_left_fan_rpm i8k_left_fan_status i8k_right_fan_rpm i8k_right_fan_status i8k_serial i8k_version ibm_brightness ibm_fan ibm_temps ibm_volume iconv_start iconv_stop if_empty if_existing if_gw if_match if_mixer_mute if_mounted if_mpd_playing if_running if_smapi_bat_installed if_up if_updatenr if_xmms2_connected image imap_messages imap_unseen ioscheduler kernel laptop_mode lines loadavg loadgraph lua lua_bar lua_gauge lua_graph lua_parse lua_read_parse machine mails mboxscan mem membar memeasyfree memfree memgauge memgraph memmax memperc mixer mixerbar mixerl mixerlbar mixerr mixerrbar moc_album moc_artist moc_bitrate moc_curtime moc_file moc_rate moc_song moc_state moc_timeleft moc_title moc_totaltime monitor monitor_number mpd_album mpd_artist mpd_bar mpd_bitrate mpd_elapsed mpd_file mpd_length mpd_name mpd_percent mpd_random mpd_repeat mpd_smart mpd_status mpd_title mpd_track mpd_vol nameserver new_mails nodename nvidia obsd_product obsd_sensors_fan obsd_sensors_temp obsd_sensors_volt obsd_vendor offset outlinecolor pb_battery platform pop3_unseen pop3_used pre_exec processes read_tcp replied_mails rss running_processes scroll seen_mails shadecolor smapi smapi_bat_bar smapi_bat_perc smapi_bat_power smapi_bat_temp sony_fanspeed stippled_hr swap swapbar swapmax swapperc sysname tab tail tcp_portmon template0 template1 template2 template3 template4 template5 template6 template7 template8 template9 texeci time to_bytes top top_io top_mem top_time totaldown totalup trashed_mails tztime unflagged_mails unforwarded_mails unreplied_mails unseen_mails updates upspeed upspeedf upspeedgraph uptime uptime_short user_names user_number user_terms user_times utime voffset voltage_mv voltage_v weather wireless_ap wireless_bitrate wireless_essid wireless_link_bar wireless_link_qual wireless_link_qual_max wireless_link_qual_perc wireless_mode words xmms2_album xmms2_artist xmms2_bar xmms2_bitrate xmms2_comment xmms2_date xmms2_duration xmms2_elapsed xmms2_genre xmms2_id xmms2_percent xmms2_playlist xmms2_size xmms2_smart xmms2_status xmms2_timesplayed xmms2_title xmms2_tracknr xmms2_url
|
||||
|
||||
hi def link ConkyrcComment Comment
|
||||
hi def link ConkyrcSetting Keyword
|
||||
|
@ -112,6 +112,10 @@ if BUILD_RSS
|
||||
rss = rss.c prss.c prss.h
|
||||
endif
|
||||
|
||||
if BUILD_WEATHER
|
||||
weather = weather.c weather.h
|
||||
endif
|
||||
|
||||
if BUILD_LUA
|
||||
lua = llua.c llua.h
|
||||
endif
|
||||
@ -154,6 +158,7 @@ conky_SOURCES = \
|
||||
$(port_monitors) \
|
||||
$(eve) \
|
||||
$(rss) \
|
||||
$(weather) \
|
||||
$(lua) \
|
||||
$(solaris) \
|
||||
timed_thread.c \
|
||||
@ -204,6 +209,7 @@ EXTRA_DIST = \
|
||||
libtcp-portmon.c \
|
||||
libtcp-portmon.h \
|
||||
rss.h \
|
||||
weather.h \
|
||||
llua.h \
|
||||
mail.h \
|
||||
mixer.h \
|
||||
|
131
src/conky.c
131
src/conky.c
@ -208,6 +208,9 @@ static void print_version(void)
|
||||
#ifdef RSS
|
||||
" * RSS\n"
|
||||
#endif /* RSS */
|
||||
#ifdef WEATHER
|
||||
" * WEATHER\n"
|
||||
#endif /* WEATHER */
|
||||
#ifdef HAVE_LUA
|
||||
" * Lua\n"
|
||||
#endif /* HAVE_LUA */
|
||||
@ -895,6 +898,12 @@ static void free_text_objects(struct text_object *root, int internal)
|
||||
free(data.rss.action);
|
||||
break;
|
||||
#endif
|
||||
#ifdef WEATHER
|
||||
case OBJ_weather:
|
||||
free(data.weather.uri);
|
||||
free(data.weather.data_type);
|
||||
break;
|
||||
#endif
|
||||
#ifdef HAVE_LUA
|
||||
case OBJ_lua:
|
||||
case OBJ_lua_parse:
|
||||
@ -2784,6 +2793,41 @@ static struct text_object *construct_text_object(const char *s,
|
||||
"[act_par] [spaces in front]");
|
||||
}
|
||||
#endif
|
||||
#ifdef WEATHER
|
||||
END OBJ(weather, 0)
|
||||
if (arg) {
|
||||
int argc, delay;
|
||||
char *icao = (char *) malloc(5 * sizeof(char));
|
||||
char *uri = (char *) malloc(128 * sizeof(char));
|
||||
char *data_type = (char *) malloc(32 * sizeof(char));
|
||||
|
||||
argc = sscanf(arg, "%4s %31s %d", icao, data_type, &delay);
|
||||
|
||||
//icao MUST BE upper-case
|
||||
char *tmp_p = icao;
|
||||
while (*tmp_p) {
|
||||
*tmp_p = toupper(*tmp_p);
|
||||
tmp_p++;
|
||||
}
|
||||
|
||||
strcpy(uri, "http://weather.noaa.gov/pub/data/observations/metar/stations/");
|
||||
strcat(uri, icao);
|
||||
strcat(uri, ".TXT");
|
||||
obj->data.weather.uri = uri;
|
||||
|
||||
obj->data.weather.data_type = data_type;
|
||||
|
||||
//The data retrieval interval is limited to half an hour
|
||||
if(delay < 30) {
|
||||
delay = 30;
|
||||
}
|
||||
obj->data.weather.delay = delay*60;
|
||||
|
||||
init_weather_info();
|
||||
} else {
|
||||
CRIT_ERR("weather needs arguments: <icao> <data_type> [delay in minutes]");
|
||||
}
|
||||
#endif
|
||||
#ifdef HAVE_LUA
|
||||
END OBJ(lua, 0)
|
||||
if (arg) {
|
||||
@ -4591,6 +4635,90 @@ static void generate_text_internal(char *p, int p_max_size,
|
||||
}
|
||||
}
|
||||
#endif
|
||||
#ifdef WEATHER
|
||||
static const char *wc[18] =
|
||||
{"", "drizzle", "rain", "hail", "soft hail",
|
||||
"snow", "snow grains", "fog", "haze", "smoke",
|
||||
"mist", "dust", "sand", "funnel cloud tornado",
|
||||
"dust/sand", "squall", "sand storm", "dust storm"};
|
||||
|
||||
OBJ(weather) {
|
||||
PWEATHER *data = get_weather_info(obj->data.weather.uri, obj->data.weather.delay);
|
||||
|
||||
if (data == NULL) {
|
||||
strncpy(p, "Error reading weather data", p_max_size);
|
||||
} else {
|
||||
if (strcmp(obj->data.weather.data_type, "last_update") == EQUAL) {
|
||||
strncpy(p, data->lastupd, p_max_size);
|
||||
} else if (strcmp(obj->data.weather.data_type, "temperature_C") == EQUAL) {
|
||||
snprintf(p, p_max_size, "%d", data->tmpC);
|
||||
} else if (strcmp(obj->data.weather.data_type, "temperature_F") == EQUAL) {
|
||||
snprintf(p, p_max_size, "%d", data->tmpF);
|
||||
} else if (strcmp(obj->data.weather.data_type, "cloud_cover") == EQUAL) {
|
||||
if (data->cc == 0) {
|
||||
strncpy(p, "", p_max_size);
|
||||
} else if (data->cc < 3) {
|
||||
strncpy(p, "clear", p_max_size);
|
||||
} else if (data->cc < 5) {
|
||||
strncpy(p, "partly cloudy", p_max_size);
|
||||
} else if (data->cc == 5) {
|
||||
strncpy(p, "cloudy", p_max_size);
|
||||
} else if (data->cc == 6) {
|
||||
strncpy(p, "overcast", p_max_size);
|
||||
} else if (data->cc == 7) {
|
||||
strncpy(p, "towering cumulus", p_max_size);
|
||||
} else {
|
||||
strncpy(p, "cumulonimbus", p_max_size);
|
||||
}
|
||||
} else if (strcmp(obj->data.weather.data_type, "pressure") == EQUAL) {
|
||||
snprintf(p, p_max_size, "%d", data->bar);
|
||||
} else if (strcmp(obj->data.weather.data_type, "wind_speed") == EQUAL) {
|
||||
snprintf(p, p_max_size, "%d", data->wind_s);
|
||||
} else if (strcmp(obj->data.weather.data_type, "wind_dir") == EQUAL) {
|
||||
if ((data->wind_d >= 349) || (data->wind_d < 12)) {
|
||||
strncpy(p, "N", p_max_size);
|
||||
} else if (data->wind_d < 33) {
|
||||
strncpy(p, "NNE", p_max_size);
|
||||
} else if (data->wind_d < 57) {
|
||||
strncpy(p, "NE", p_max_size);
|
||||
} else if (data->wind_d < 79) {
|
||||
strncpy(p, "ENE", p_max_size);
|
||||
} else if (data->wind_d < 102) {
|
||||
strncpy(p, "E", p_max_size);
|
||||
} else if (data->wind_d < 124) {
|
||||
strncpy(p, "ESE", p_max_size);
|
||||
} else if (data->wind_d < 147) {
|
||||
strncpy(p, "SE", p_max_size);
|
||||
} else if (data->wind_d < 169) {
|
||||
strncpy(p, "SSE", p_max_size);
|
||||
} else if (data->wind_d < 192) {
|
||||
strncpy(p, "S", p_max_size);
|
||||
} else if (data->wind_d < 214) {
|
||||
strncpy(p, "SSW", p_max_size);
|
||||
} else if (data->wind_d < 237) {
|
||||
strncpy(p, "SW", p_max_size);
|
||||
} else if (data->wind_d < 259) {
|
||||
strncpy(p, "WSW", p_max_size);
|
||||
} else if (data->wind_d < 282) {
|
||||
strncpy(p, "W", p_max_size);
|
||||
} else if (data->wind_d < 304) {
|
||||
strncpy(p, "WNW", p_max_size);
|
||||
} else if (data->wind_d < 327) {
|
||||
strncpy(p, "NW", p_max_size);
|
||||
} else if (data->wind_d < 349) {
|
||||
strncpy(p, "NNW", p_max_size);
|
||||
};
|
||||
} else if (strcmp(obj->data.weather.data_type, "wind_dir_DEG") == EQUAL) {
|
||||
snprintf(p, p_max_size, "%d", data->wind_d);
|
||||
|
||||
} else if (strcmp(obj->data.weather.data_type, "humidity") == EQUAL) {
|
||||
snprintf(p, p_max_size, "%d", data->hmid);
|
||||
} else if (strcmp(obj->data.weather.data_type, "weather") == EQUAL) {
|
||||
strncpy(p, wc[data->wc], p_max_size);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
#ifdef HAVE_LUA
|
||||
OBJ(lua) {
|
||||
char *str = llua_getstring(obj->data.s);
|
||||
@ -7464,6 +7592,9 @@ static void clean_up(void)
|
||||
#ifdef RSS
|
||||
free_rss_info();
|
||||
#endif
|
||||
#ifdef WEATHER
|
||||
free_weather_info();
|
||||
#endif
|
||||
#ifdef HAVE_LUA
|
||||
llua_close();
|
||||
#endif /* HAVE_LUA */
|
||||
|
@ -91,6 +91,10 @@ char *strndup(const char *s, size_t n);
|
||||
#include "rss.h"
|
||||
#endif
|
||||
|
||||
#ifdef WEATHER
|
||||
#include "weather.h"
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_LUA
|
||||
#include "llua.h"
|
||||
#endif
|
||||
@ -204,6 +208,9 @@ enum {
|
||||
#ifdef APCUPSD
|
||||
INFO_APCUPSD = 32,
|
||||
#endif
|
||||
#ifdef WEATHER
|
||||
INFO_WEATHER = 33,
|
||||
#endif
|
||||
};
|
||||
|
||||
/* get_battery_stuff() item selector
|
||||
|
@ -374,6 +374,9 @@ enum text_object_type {
|
||||
#ifdef RSS
|
||||
OBJ_rss,
|
||||
#endif /* RSS */
|
||||
#ifdef WEATHER
|
||||
OBJ_weather,
|
||||
#endif /* WEATHER */
|
||||
#ifdef HAVE_LUA
|
||||
OBJ_lua,
|
||||
OBJ_lua_parse,
|
||||
@ -540,6 +543,13 @@ struct text_object {
|
||||
int delay;
|
||||
unsigned int nrspaces;
|
||||
} rss;
|
||||
#endif
|
||||
#ifdef WEATHER
|
||||
struct {
|
||||
char *uri;
|
||||
char *data_type;
|
||||
int delay;
|
||||
} weather;
|
||||
#endif
|
||||
struct {
|
||||
char *text;
|
||||
|
497
src/weather.c
Normal file
497
src/weather.c
Normal file
@ -0,0 +1,497 @@
|
||||
/* Conky, a system monitor, based on torsmo
|
||||
*
|
||||
* Any original torsmo code is licensed under the BSD license
|
||||
*
|
||||
* All code written since the fork of torsmo is licensed under the GPL
|
||||
*
|
||||
* Please see COPYING for details
|
||||
*
|
||||
* Copyright (c) 2004, Hannu Saransaari and Lauri Hakkarainen
|
||||
* Copyright (c) 2005-2009 Brenden Matthews, Philip Kovacs, et. al.
|
||||
* (see AUTHORS)
|
||||
* All rights reserved.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "conky.h"
|
||||
#include "logging.h"
|
||||
#include "weather.h"
|
||||
#include <time.h>
|
||||
#include <ctype.h>
|
||||
#include <curl/curl.h>
|
||||
#include <curl/types.h>
|
||||
#include <curl/easy.h>
|
||||
|
||||
#define MAX_LOCATIONS 3
|
||||
|
||||
/* Possible sky conditions */
|
||||
#define NUM_CC_CODES 7
|
||||
const char *CC_CODES[NUM_CC_CODES] =
|
||||
{"SKC", "CLR", "FEW", "SCT", "BKN", "OVC", "TCU"};
|
||||
|
||||
/* Possible weather conditions */
|
||||
#define NUM_WC_CODES 17
|
||||
const char *WC_CODES[NUM_WC_CODES] =
|
||||
{"DZ", "RA", "GR", "GS", "SN", "SG", "FG", "HZ", "FU", "BR", "DU", "SA",
|
||||
"FC", "PO", "SQ", "SS", "DS"};
|
||||
|
||||
/*
|
||||
* TODO: This could be made common with the one used in prss.c
|
||||
*
|
||||
*/
|
||||
|
||||
struct WMemoryStruct {
|
||||
char *memory;
|
||||
size_t size;
|
||||
};
|
||||
|
||||
typedef struct location_ {
|
||||
char *uri;
|
||||
int last_update;
|
||||
PWEATHER *data;
|
||||
} location;
|
||||
|
||||
int num_locations = 0;
|
||||
location locations[MAX_LOCATIONS];
|
||||
|
||||
/*
|
||||
* TODO: This could be made common with the one used in prss.c
|
||||
*
|
||||
*/
|
||||
|
||||
size_t WWriteMemoryCallback(void *ptr, size_t size, size_t nmemb, void *data)
|
||||
{
|
||||
size_t realsize = size * nmemb;
|
||||
struct WMemoryStruct *mem = (struct WMemoryStruct *) data;
|
||||
|
||||
mem->memory = (char *) realloc(mem->memory, mem->size + realsize + 1);
|
||||
if (mem->memory) {
|
||||
memcpy(&(mem->memory[mem->size]), ptr, realsize);
|
||||
mem->size += realsize;
|
||||
mem->memory[mem->size] = 0;
|
||||
}
|
||||
return realsize;
|
||||
}
|
||||
|
||||
int weather_delay(int *last, int delay)
|
||||
{
|
||||
time_t now = time(NULL);
|
||||
|
||||
if ((!*last) || (now >= *last + delay)) {
|
||||
*last = now;
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void init_weather_info(void)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < MAX_LOCATIONS; i++) {
|
||||
locations[i].uri = NULL;
|
||||
locations[i].data = NULL;
|
||||
locations[i].last_update = 0;
|
||||
}
|
||||
}
|
||||
|
||||
void free_weather_info(void)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < num_locations; i++) {
|
||||
if (locations[i].uri != NULL) {
|
||||
free(locations[i].uri);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int rel_humidity(int dew_point, int air) {
|
||||
const float a = 17.27f;
|
||||
const float b = 237.7f;
|
||||
|
||||
float g = a*dew_point/(b+dew_point);
|
||||
return (int)(100.f*expf(g-a*air/(b+air)));
|
||||
}
|
||||
|
||||
/*
|
||||
* Horrible hack to avoid using regexes
|
||||
*
|
||||
*/
|
||||
|
||||
static inline void parse_token(PWEATHER *res, char *token) {
|
||||
|
||||
int i;
|
||||
char s_tmp[64];
|
||||
|
||||
//Check all tokens 2 chars long
|
||||
if (strlen(token) == 2 ) {
|
||||
|
||||
//Check if token is a weather condition
|
||||
for (i=0; i<2; i++) {
|
||||
if (!isalpha(token[i])) break;
|
||||
}
|
||||
if (i==2) {
|
||||
for(i=0; i<NUM_WC_CODES; i++) {
|
||||
if (!strncmp(token, WC_CODES[i], 2)) {
|
||||
res->wc=i+1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
//Check for CB
|
||||
if (!strcmp(token, "CB")) {
|
||||
res->cc = 8;
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//Check all tokens 3 chars long
|
||||
if (strlen(token) == 3 ) {
|
||||
|
||||
//Check if token is a modified weather condition
|
||||
if ((token[0] == '+') || (token[0] == '-')) {
|
||||
for (i=1; i<3; i++) {
|
||||
if (!isalpha(token[i])) break;
|
||||
}
|
||||
if (i==3) {
|
||||
for(i=0; i<NUM_WC_CODES; i++) {
|
||||
if (!strncmp(&token[1], WC_CODES[i], 2)) {
|
||||
res->wc=i+1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
//Check for NCD
|
||||
if (!strcmp(token, "NCD")) {
|
||||
res->cc = 1;
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//Check all tokens 4 chars long
|
||||
if (strlen(token) == 4 ) {
|
||||
|
||||
//Check if token is an icao
|
||||
for (i=0; i<4; i++) {
|
||||
if (!isalpha(token[i])) break;
|
||||
}
|
||||
if (i==4) return;
|
||||
|
||||
}
|
||||
|
||||
//Check all tokens 5 chars long
|
||||
if (strlen(token) == 5 ) {
|
||||
|
||||
//Check for CAVOK
|
||||
if (!strcmp(token, "CAVOK")) {
|
||||
res->cc = 1;
|
||||
return;
|
||||
}
|
||||
|
||||
//Check if token is the temperature
|
||||
for (i=0; i<2; i++) {
|
||||
if (!isdigit(token[i])) break;
|
||||
}
|
||||
if ((i==2) && (token[2] == '/')) {
|
||||
for (i=3; i<5; i++) {
|
||||
if (!isdigit(token[i])) break;
|
||||
}
|
||||
if (i==5) {
|
||||
//First 2 digits gives the air temperature
|
||||
res->tmpC=atoi(token);
|
||||
|
||||
//4th and 5th digits gives the dew point temperature
|
||||
res->dew=atoi(&token[3]);
|
||||
|
||||
//Compute humidity
|
||||
res->hmid = rel_humidity(res->dew, res->tmpC);
|
||||
|
||||
//Convert to Fahrenheit (faster here than in conky.c)
|
||||
res->tmpF = (res->tmpC*9)/5 + 32;
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
//Check if token is the pressure
|
||||
if ((token[0] == 'Q') || (token[0] == 'A')) {
|
||||
for (i=1; i<5; i++) {
|
||||
if (!isdigit(token[i])) break;
|
||||
}
|
||||
if (i==5) {
|
||||
if (token[0] == 'A') {
|
||||
//Convert inches of mercury to mbar
|
||||
res->bar = (int)(atoi(&token[1])*0.338637526f);
|
||||
return;
|
||||
}
|
||||
|
||||
//Last 4 digits is pressure im mbar
|
||||
res->bar = atoi(&token[1]);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//Check all tokens 6 chars long
|
||||
if (strlen(token) == 6 ) {
|
||||
|
||||
//Check if token is the cloud cover
|
||||
for (i=0; i<3; i++) {
|
||||
if (!isalpha(token[i])) break;
|
||||
}
|
||||
if (i==3) {
|
||||
for (i=3; i<6; i++) {
|
||||
if (!isdigit(token[i])) break;
|
||||
}
|
||||
if (i==6) {
|
||||
//Check if first 3 digits gives the cloud cover condition
|
||||
for(i=0; i<NUM_CC_CODES; i++) {
|
||||
if (!strncmp(token, CC_CODES[i], 3)) {
|
||||
res->cc=i+1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
//Check if token is positive temp and negative dew
|
||||
for (i=0; i<2; i++) {
|
||||
if (!isdigit(token[i])) break;
|
||||
}
|
||||
if ((i==2) && (token[2] == '/') && (token[3] == 'M')) {
|
||||
for (i=4; i<6; i++) {
|
||||
if (!isdigit(token[i])) break;
|
||||
}
|
||||
if (i==6) {
|
||||
//1st and 2nd digits gives the temperature
|
||||
res->tmpC = atoi(token);
|
||||
|
||||
//5th and 6th digits gives the dew point temperature
|
||||
res->dew = -atoi(&token[4]);
|
||||
|
||||
//Compute humidity
|
||||
res->hmid = rel_humidity(res->dew, res->tmpC);
|
||||
|
||||
//Convert to Fahrenheit (faster here than in conky.c)
|
||||
res->tmpF = (res->tmpC*9)/5 + 32;
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//Check all tokens 7 chars long
|
||||
if (strlen(token) == 7 ) {
|
||||
|
||||
//Check if token is the observation time
|
||||
for (i=0; i<6; i++) {
|
||||
if (!isdigit(token[i])) break;
|
||||
}
|
||||
if ((i==6) && (token[6] == 'Z')) return;
|
||||
|
||||
//Check if token is the wind speed/direction in knots
|
||||
for (i=0; i<5; i++) {
|
||||
if (!isdigit(token[i])) break;
|
||||
}
|
||||
if ((i==5) && (token[5] == 'K') && (token[6] == 'T')) {
|
||||
|
||||
//First 3 digits are wind direction
|
||||
strncpy(s_tmp, token, 3);
|
||||
res->wind_d=atoi(s_tmp);
|
||||
|
||||
//4th and 5th digit are wind speed in knots (convert to km/hr)
|
||||
res->wind_s = (int)(atoi(&token[3])*1.852);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
//Check if token is negative temperature
|
||||
if ((token[0] == 'M') && (token[4] == 'M')) {
|
||||
for (i=1; i<3; i++) {
|
||||
if (!isdigit(token[i])) break;
|
||||
}
|
||||
if ((i==3) && (token[3] == '/')) {
|
||||
for (i=5; i<7; i++) {
|
||||
if (!isdigit(token[i])) break;
|
||||
}
|
||||
if (i==7) {
|
||||
//2nd and 3rd digits gives the temperature
|
||||
res->tmpC = -atoi(&token[1]);
|
||||
|
||||
//6th and 7th digits gives the dew point temperature
|
||||
res->dew = -atoi(&token[5]);
|
||||
|
||||
//Compute humidity
|
||||
res->hmid = rel_humidity(res->dew, res->tmpC);
|
||||
|
||||
//Convert to Fahrenheit (faster here than in conky.c)
|
||||
res->tmpF = (res->tmpC*9)/5 + 32;
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//Check if token is wind variability
|
||||
for (i=0; i<3; i++) {
|
||||
if (!isdigit(token[i])) break;
|
||||
}
|
||||
if ((i==3) && (token[3] == 'V')) {
|
||||
for (i=4; i<7; i++) {
|
||||
if (!isdigit(token[i])) break;
|
||||
}
|
||||
if (i==7) return;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//Check all tokens 8 chars long
|
||||
if (strlen(token) == 8 ) {
|
||||
|
||||
//Check if token is the wind speed/direction in m/s
|
||||
for (i=0; i<5; i++) {
|
||||
if (!isdigit(token[i])) break;
|
||||
}
|
||||
if ((i==5)&&(token[5] == 'M')&&(token[6] == 'P')&&(token[7] == 'S')) {
|
||||
|
||||
//First 3 digits are wind direction
|
||||
strncpy(s_tmp, token, 3);
|
||||
res->wind_d=atoi(s_tmp);
|
||||
|
||||
//4th and 5th digit are wind speed in m/s (convert to km/hr)
|
||||
res->wind_s = (int)(atoi(&token[3])*3.6);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//printf("token : %s\n", token);
|
||||
}
|
||||
|
||||
static inline PWEATHER *parse_weather(const char *data)
|
||||
{
|
||||
char s_tmp[256];
|
||||
const char delim[] = " ";
|
||||
|
||||
PWEATHER *res = malloc(sizeof(PWEATHER));
|
||||
memset(res, 0, sizeof(PWEATHER));
|
||||
|
||||
//Divide time stamp and metar data
|
||||
if (sscanf(data, "%[^'\n']\n%[^'\n']", res->lastupd, s_tmp) == 2) {
|
||||
|
||||
//Process all tokens
|
||||
char *p_tok = NULL;
|
||||
char *p_save = NULL;
|
||||
|
||||
if ((p_tok = strtok_r(s_tmp, delim, &p_save)) != NULL) {
|
||||
do {
|
||||
|
||||
parse_token(res, p_tok);
|
||||
p_tok = strtok_r(NULL, delim, &p_save);
|
||||
|
||||
} while (p_tok != NULL);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
else {
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
PWEATHER *get_weather_info(char *uri, int delay)
|
||||
{
|
||||
CURL *curl = NULL;
|
||||
CURLcode res;
|
||||
|
||||
// pointers to struct
|
||||
location *curloc = NULL;
|
||||
PWEATHER *curdata = NULL;
|
||||
int *last_update = 0;
|
||||
|
||||
int i;
|
||||
|
||||
// curl temps
|
||||
struct WMemoryStruct chunk;
|
||||
|
||||
chunk.memory = NULL;
|
||||
chunk.size = 0;
|
||||
|
||||
// first seek for the uri in list
|
||||
for (i = 0; i < num_locations; i++) {
|
||||
if (locations[i].uri != NULL) {
|
||||
if (!strcmp(locations[i].uri, uri)) {
|
||||
curloc = &locations[i];
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!curloc) { // new location
|
||||
if (num_locations == MAX_LOCATIONS) {
|
||||
return NULL;
|
||||
}
|
||||
curloc = &locations[num_locations];
|
||||
curloc->uri = strndup(uri, text_buffer_size);
|
||||
num_locations++;
|
||||
}
|
||||
|
||||
last_update = &curloc->last_update;
|
||||
curdata = curloc->data;
|
||||
|
||||
// wait for delay to pass
|
||||
if (!weather_delay(last_update, delay)) {
|
||||
return curdata;
|
||||
}
|
||||
|
||||
// clean up old data
|
||||
if (curdata != NULL) {
|
||||
free(curdata);
|
||||
curdata = NULL;
|
||||
}
|
||||
|
||||
curl = curl_easy_init();
|
||||
if (curl) {
|
||||
curl_easy_setopt(curl, CURLOPT_URL, uri);
|
||||
curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 1);
|
||||
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, WWriteMemoryCallback);
|
||||
curl_easy_setopt(curl, CURLOPT_WRITEDATA, (void *) &chunk);
|
||||
curl_easy_setopt(curl, CURLOPT_USERAGENT, "conky-weather/1.0");
|
||||
|
||||
res = curl_easy_perform(curl);
|
||||
if (chunk.size) {
|
||||
curdata = parse_weather(chunk.memory);
|
||||
free(chunk.memory);
|
||||
} else {
|
||||
ERR("No data from server");
|
||||
}
|
||||
|
||||
curl_easy_cleanup(curl);
|
||||
}
|
||||
|
||||
curloc->data = curdata;
|
||||
|
||||
return curdata;
|
||||
}
|
50
src/weather.h
Normal file
50
src/weather.h
Normal file
@ -0,0 +1,50 @@
|
||||
/* Conky, a system monitor, based on torsmo
|
||||
*
|
||||
* Any original torsmo code is licensed under the BSD license
|
||||
*
|
||||
* All code written since the fork of torsmo is licensed under the GPL
|
||||
*
|
||||
* Please see COPYING for details
|
||||
*
|
||||
* Copyright (c) 2004, Hannu Saransaari and Lauri Hakkarainen
|
||||
* Copyright (c) 2005-2009 Brenden Matthews, Philip Kovacs, et. al.
|
||||
* (see AUTHORS)
|
||||
* All rights reserved.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef WEATHER_H_
|
||||
#define WEATHER_H_
|
||||
|
||||
/* WEATHER data */
|
||||
typedef struct PWEATHER_ {
|
||||
char lastupd[17];
|
||||
int tmpC;
|
||||
int tmpF;
|
||||
int dew;
|
||||
int cc;
|
||||
int bar;
|
||||
int wind_s;
|
||||
int wind_d;
|
||||
int hmid;
|
||||
int wc;
|
||||
} PWEATHER;
|
||||
|
||||
/* Prototypes */
|
||||
PWEATHER *get_weather_info(char *uri, int delay);
|
||||
void init_weather_info(void);
|
||||
void free_weather_info(void);
|
||||
|
||||
#endif /*WEATHER_H_*/
|
Loading…
Reference in New Issue
Block a user