From: Brenden Matthews Date: Mon, 13 Jul 2009 05:31:57 +0000 (-0600) Subject: Refactor some of the new weather code, fix docs. X-Git-Url: https://vcs.maemo.org/git/?a=commitdiff_plain;h=e1011c0d13b6196f1439e3f58440ccca9bd39857;p=monky Refactor some of the new weather code, fix docs. I moved the weather stuff into its own thread, and also fixed up some abuse of formatting throughout the docs. Hopefully we can keep things a little more uniform from now on. --- diff --git a/doc/config_settings.xsl b/doc/config_settings.xsl index af77346..4222d3c 100644 --- a/doc/config_settings.xsl +++ b/doc/config_settings.xsl @@ -18,7 +18,7 @@ - Conky Variables + Conky configuration settings @@ -40,7 +40,7 @@ - + - diff --git a/doc/lua.xml b/doc/lua.xml index 807fc85..63bf24b 100644 --- a/doc/lua.xml +++ b/doc/lua.xml @@ -26,60 +26,59 @@ drawable - visual - + display - width - + height - + border_inner_margin - border_outer_margin - border_width - text_start_x - text_start_y - text_width - text_height - diff --git a/doc/lua.xsl b/doc/lua.xsl index 06f54d7..b723ec7 100644 --- a/doc/lua.xsl +++ b/doc/lua.xsl @@ -18,7 +18,7 @@ - + - diff --git a/doc/variables.xml b/doc/variables.xml index fd494c4..3dbfbec 100644 --- a/doc/variables.xml +++ b/doc/variables.xml @@ -655,25 +655,25 @@ - Number of the desktop on which conky is running + Number of the desktop on which conky is running - + - Number of desktops + Name of the desktop on which conky is running - + - Name of the desktop on which conky is running + Number of desktops @@ -1532,13 +1532,13 @@ and right side types are: - double: argument consists of only + doubleArgument consists of only digits and a single dot. - long: argument consists of only + longArgument consists of only digits. - string: argument is enclosed in + stringArgument is enclosed in quotation mark or the checks for double and long failed before. Valid operands are: '>', '<', '>=', @@ -2360,23 +2360,29 @@ other values as integer. - threshold: the thresholdtemperature - at which the gpu slows down + thresholdThe thresholdtemperature at + which the gpu slows down - temp: gives the gpu current + tempTives the gpu current temperature - ambient: gives current air - temperature near GPU case + ambient + + - gpufreq: gives the current gpu - frequency + gpufreq + + - memfreq: gives the current mem - frequency + memfreq + + - imagequality: which imagequality - should be choosen by OpenGL applications + imagequality + + @@ -2413,20 +2419,25 @@ must be specified. Valid items are: - status: Display if battery is fully - charged, charging, discharging or absent (running on - AC) + status + + - percent: Display charge of battery - in percent, if charging or discharging. Nothing will be - displayed, if battery is fully charged or - absent. + percent + + - time: Display the time remaining - until the battery will be fully charged or discharged - at current rate. Nothing is displayed, if battery is - absent or if it's present but fully charged and not - discharging. + time + + @@ -2771,68 +2782,102 @@ (ip4 only at present) - TCP port monitor for specified local ports. Port - numbers must be in the range 1 to 65535. Valid items are: - - - count- total number of connections - in the range - - rip- remote ip address - - rhost- remote host name - - rport- remote port number - - rservice- remote service name from - /etc/services - - lip- local ip address - - lhost- local host name - - lport- local port number - - lservice- local service name from - /etc/services - The connection index provides you with access - to each connection in the port monitor. The monitor will - return information for index values from 0 to n-1 - connections. Values higher than n-1 are simply ignored. For - the "count" item, the connection index must be omitted. It - is required for all other items. - - Examples: - - ${tcp_portmon 6881 6999 count}- - displays the number of connections in the bittorrent - port range - - ${tcp_portmon 22 22 rip 0}- displays - the remote host ip of the first sshd - connection - - ${tcp_portmon 22 22 rip 9}- displays - the remote host ip of the tenth sshd - connection - - ${tcp_portmon 1 1024 rhost 0}- - displays the remote host name of the first connection - on a privileged port - - ${tcp_portmon 1 1024 rport 4}- - displays the remote host port of the fifth connection - on a privileged port - - ${tcp_portmon 1 65535 lservice 14}- - displays the local service name of the fifteenth - connection in the range of all ports - Note that port monitor variables which share - the same port range actually refer to the same monitor, so - many references to a single port range for different items - and different indexes all use the same monitor internally. - In other words, the program avoids creating redundant - monitors. + + TCP port monitor for specified local ports. Port + numbers must be in the range 1 to 65535. Valid items + are: + + + count + + + + rip + + + + rhost + + + + rport + + + + rservice + + + + lip + + + + lhost + + + + lport + + + + lservice + + + + The connection index provides you with access to + each connection in the port monitor. The monitor will + return information for index values from 0 to n-1 + connections. Values higher than n-1 are simply ignored. + For the "count" item, the connection index must be + omitted. It is required for all other items. + Examples: + + + ${tcp_portmon 6881 6999 + count} + + + + ${tcp_portmon 22 22 rip 0} + + + + ${tcp_portmon 22 22 rip 9} + + + + ${tcp_portmon 1 1024 rhost + 0} + + + + ${tcp_portmon 1 1024 rport + 4} + + + + ${tcp_portmon 1 65535 lservice + 14} + + + + Note that port monitor variables which share the + same port range actually refer to the same monitor, so + many references to a single port range for different + items and different indexes all use the same monitor + internally. In other words, the program avoids creating + redundant monitors. + @@ -2843,59 +2888,63 @@ - Evaluate the content of the templateN - configuration variable (where N is a value between 0 and 9, - inclusively), applying substitutions as described in the - documentation of the corresponding configuration variable. - The number of arguments is optional, but must match the - highest referred index in the template. You can use the - same special sequences in each argument as the ones valid - for a template definition, e.g. to allow an argument to - contain a whitespace. Also simple nesting of templates is - possible this way. - - Here are some examples of template definitions: - - template0 $\1\2 - template1 \1: ${fs_used \2} / ${fs_size - \2} - template2 \1 \2 - The following list shows sample usage of the - templates defined above, with the equivalent syntax when - not using any template at all: - - - - - using template - same without template - - - - - ${template0 node name} - $nodename - - - ${template1 root /} - root: ${fs_free /} / ${fs_size - /} - - - - ${template1 - ${template2\ disk\ root} - /} - - - disk root: ${fs_free /} - / ${fs_size /} - - - - -
-
+ + Evaluate the content of the templateN + configuration variable (where N is a value between 0 + and 9, inclusively), applying substitutions as + described in the documentation of the corresponding + configuration variable. The number of arguments is + optional, but must match the highest referred index in + the template. You can use the same special sequences in + each argument as the ones valid for a template + definition, e.g. to allow an argument to contain a + whitespace. Also simple nesting of templates is + possible this way. + Here are some examples of template + definitions: + + template0 $\1\2 + template1 \1: ${fs_used \2} / ${fs_size + \2} + template2 \1 \2 + + The following list shows sample usage of the + templates defined above, with the equivalent syntax + when not using any template at all: + + + + + using template + same without template + + + + + ${template0 node name} + $nodename + + + ${template1 root /} + root: ${fs_free /} / ${fs_size + /} + + + + ${template1 + ${template2\ disk\ root} + /} + + + disk root: + ${fs_free /} / ${fs_size + /} + + + + +
+
@@ -3236,26 +3285,61 @@ - - - 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. - + + + + 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/). For the URI, you can use any METAR source, but a good example is http://weather.noaa.gov/pub/data/observations/metar/stations/ (from the US NOAA). + 'data_type' must be one of the following: + + + last_update + + + + temperature + + + + cloud_cover + + + + pressurer + + + + wind_speed + + + + wind_dir + + + + wind_dir_DEG + + + + humidity + + + + weather + + + + 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. + diff --git a/doc/variables.xsl b/doc/variables.xsl index 9a2bf41..2c1eb3d 100644 --- a/doc/variables.xsl +++ b/doc/variables.xsl @@ -18,7 +18,7 @@ - Lua API + Conky Objects @@ -29,7 +29,7 @@ - + - diff --git a/extras/nano/conky.nanorc b/extras/nano/conky.nanorc index e1f35c7..2635169 100644 --- a/extras/nano/conky.nanorc +++ b/extras/nano/conky.nanorc @@ -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|desktop|desktop_number|desktop_name|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|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|swapfree|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 "\<(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|desktop|desktop_name|desktop_number|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|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|swapfree|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 "(\{|\}|\(|\)|\;|\]|\[|`|\\|\$|<|>|!|=|&|\|)" diff --git a/extras/vim/syntax/conkyrc.vim b/extras/vim/syntax/conkyrc.vim index d2b88a3..60de1c0 100644 --- a/extras/vim/syntax/conkyrc.vim +++ b/extras/vim/syntax/conkyrc.vim @@ -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 desktop desktop_number desktop_name 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 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 swapfree 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 +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 desktop desktop_name desktop_number 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 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 swapfree 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 diff --git a/src/common.c b/src/common.c index 721c10b..10305f5 100644 --- a/src/common.c +++ b/src/common.c @@ -512,3 +512,21 @@ unsigned int round_to_int(float f) return 0; } } + +/* utility function used by RSS and Weather stuff for a curl callback. + */ +size_t WriteMemoryCallback(void *ptr, size_t size, size_t nmemb, void *data) +{ + size_t realsize = size * nmemb; + struct MemoryStruct *mem = (struct MemoryStruct *) 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; +} + + diff --git a/src/common.h b/src/common.h index ddf1427..32241dd 100644 --- a/src/common.h +++ b/src/common.h @@ -89,4 +89,14 @@ int get_battery_perct(const char *bat); int get_battery_perct_bar(const char *bat); void get_battery_short_status(char *buf, unsigned int n, const char *bat); +/* + * used by RSS and Weather + */ +struct MemoryStruct { + char *memory; + size_t size; +}; + +size_t WriteMemoryCallback(void *ptr, size_t size, size_t nmemb, void *data); + #endif /* _COMMON_H */ diff --git a/src/conky.c b/src/conky.c index ce0b9e4..8c4f06a 100644 --- a/src/conky.c +++ b/src/conky.c @@ -2814,37 +2814,35 @@ static struct text_object *construct_text_object(const char *s, #ifdef WEATHER END OBJ(weather, 0) if (arg) { - int argc, delay; + int argc, interval; char *icao = (char *) malloc(5 * sizeof(char)); char *uri = (char *) malloc(128 * sizeof(char)); char *data_type = (char *) malloc(32 * sizeof(char)); char *tmp_p; - argc = sscanf(arg, "%4s %31s %d", icao, data_type, &delay); + argc = sscanf(arg, "%127s %4s %31s %d", uri, icao, data_type, &interval); //icao MUST BE upper-case tmp_p = icao; while (*tmp_p) { - *tmp_p = toupper(*tmp_p); - 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; + // The data retrieval interval is limited to half an hour + if (interval < 30) { + interval = 30; } - obj->data.weather.delay = delay*60; - - init_weather_info(); + obj->data.weather.interval = interval * 60; // convert to seconds } else { - CRIT_ERR("weather needs arguments: [delay in minutes]"); + CRIT_ERR("weather needs arguments: [interval in minutes]"); } #endif #ifdef HAVE_LUA @@ -4639,87 +4637,7 @@ static void generate_text_internal(char *p, int p_max_size, #endif #ifdef WEATHER OBJ(weather) { - PWEATHER *data = get_weather_info(obj->data.weather.uri, obj->data.weather.delay); - - 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"}; - - - 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); - } - } + process_weather_info(p, p_max_size, obj->data.weather.uri, obj->data.weather.data_type, obj->data.weather.interval); } #endif #ifdef HAVE_LUA @@ -7485,6 +7403,12 @@ static void reload_config(void) tcp_portmon_clear(); #endif +#ifdef RSS + free_rss_info(); +#endif +#ifdef WEATHER + free_weather_info(); +#endif #ifdef HAVE_LUA llua_close(); #endif /* HAVE_LUA */ diff --git a/src/rss.c b/src/rss.c index d345fa5..75a6595 100644 --- a/src/rss.c +++ b/src/rss.c @@ -1,9 +1,5 @@ /* 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) 2007 Toni Spets @@ -36,11 +32,6 @@ #define MAX_FEEDS 16 -struct MemoryStruct { - char *memory; - size_t size; -}; - typedef struct feed_ { char *uri; int last_update; @@ -50,20 +41,6 @@ typedef struct feed_ { int num_feeds = 0; feed feeds[MAX_FEEDS]; -size_t WriteMemoryCallback(void *ptr, size_t size, size_t nmemb, void *data) -{ - size_t realsize = size * nmemb; - struct MemoryStruct *mem = (struct MemoryStruct *) 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 rss_delay(int *wait_time, int delay) { time_t now = time(NULL); diff --git a/src/temphelper.c b/src/temphelper.c index a90059b..fe6b2f5 100644 --- a/src/temphelper.c +++ b/src/temphelper.c @@ -30,20 +30,17 @@ /* default to output in celsius */ static enum TEMP_UNIT output_unit = TEMP_CELSIUS; -static double -fahrenheit_to_celsius(double n) +static double fahrenheit_to_celsius(double n) { return ((n - 32) * 5 / 9); } -static double -celsius_to_fahrenheit(double n) +static double celsius_to_fahrenheit(double n) { return ((n * 9 / 5) + 32); } -int -set_temp_output_unit(const char *name) +int set_temp_output_unit(const char *name) { long i; int rc = 0; @@ -66,8 +63,7 @@ set_temp_output_unit(const char *name) return rc; } -static double -convert_temp_output(double n, enum TEMP_UNIT input_unit) +static double convert_temp_output(double n, enum TEMP_UNIT input_unit) { if (input_unit == output_unit) return n; diff --git a/src/text_object.h b/src/text_object.h index 304eed0..75ae83e 100644 --- a/src/text_object.h +++ b/src/text_object.h @@ -545,13 +545,15 @@ struct text_object { int act_par; int delay; unsigned int nrspaces; + timed_thread *p_timed_thread; } rss; #endif #ifdef WEATHER struct { char *uri; char *data_type; - int delay; + int interval; + timed_thread *p_timed_thread; } weather; #endif struct { diff --git a/src/weather.c b/src/weather.c index dc5ab13..94bc7d3 100644 --- a/src/weather.c +++ b/src/weather.c @@ -1,12 +1,8 @@ -/* 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 +/* + * Conky, a system monitor, based on torsmo * * 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. @@ -28,6 +24,7 @@ #include "conky.h" #include "logging.h" #include "weather.h" +#include "temphelper.h" #include #include #include @@ -38,98 +35,84 @@ /* Possible sky conditions */ #define NUM_CC_CODES 6 -const char *CC_CODES[NUM_CC_CODES] = - {"SKC", "CLR", "FEW", "SCT", "BKN", "OVC"}; +const char *CC_CODES[NUM_CC_CODES] = { + "SKC", "CLR", "FEW", "SCT", "BKN", "OVC" +}; /* Possible weather modifiers */ #define NUM_WM_CODES 9 -const char *WM_CODES[NUM_WM_CODES] = - {"VC", "MI", "BC", "PR", "TS", "BL", "SH", "DR", "FZ"}; +const char *WM_CODES[NUM_WM_CODES] = { + "VC", "MI", "BC", "PR", "TS", "BL", + "SH", "DR", "FZ" +}; /* 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; +const char *WC_CODES[NUM_WC_CODES] = { + "DZ", "RA", "GR", "GS", "SN", "SG", + "FG", "HZ", "FU", "BR", "DU", "SA", + "FC", "PO", "SQ", "SS", "DS", }; typedef struct location_ { char *uri; int last_update; - PWEATHER *data; + PWEATHER data; + timed_thread *p_timed_thread; + struct location_ *next; } location; -int num_locations = 0; -location locations[MAX_LOCATIONS]; +static location *locations_head = 0; -/* - * 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) +location *find_location(char *uri) { - time_t now = time(NULL); - - if ((!*last) || (now >= *last + delay)) { - *last = now; - return 1; + location *tail = locations_head; + location *new = 0; + while (tail) { + if (tail->uri && + strcmp(tail->uri, uri) == EQUAL) { + return tail; + } + tail = tail->next; } - - 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; + if (!tail) { // new location!!!!!!! + new = malloc(sizeof(location)); + memset(new, 0, sizeof(location)); + new->uri = strndup(uri, text_buffer_size); + tail = locations_head; + while (tail && tail->next) { + tail = tail->next; + } + if (!tail) { + // omg the first one!!!!!!! + locations_head = new; + } else { + tail->next = new; + } } + return new; } void free_weather_info(void) { - int i; - - for (i = 0; i < num_locations; i++) { - if (locations[i].uri != NULL) { - free(locations[i].uri); - } + location *tail = locations_head; + location *last = 0; + + while (tail) { + if (tail->uri) free(tail->uri); + last = tail; + tail = tail->next; + free(last); } + locations_head = 0; } int rel_humidity(int dew_point, int air) { - const float a = 17.27f; - const float b = 237.7f; + 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))); + float g = a*dew_point/(b+dew_point); + return (int)(100.f*expf(g-a*air/(b+air))); } /* @@ -139,401 +122,467 @@ int rel_humidity(int dew_point, int air) { static inline void parse_token(PWEATHER *res, char *token) { - int i; - char s_tmp[64]; - - switch (strlen(token)) { - - //Check all tokens 2 chars long - case 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; iwc=i+1; - break; - } - } - return; - } - - //Check for CB - if (!strcmp(token, "CB")) { - res->cc = 8; - return; - } - - break; - - //Check all tokens 3 chars long - case 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; iwc=i+1; - break; - } - } - return; + int i; + char s_tmp[64]; + + switch (strlen(token)) { + + //Check all tokens 2 chars long + case 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; iwc=i+1; + break; + } + } + return; + } + + //Check for CB + if (!strcmp(token, "CB")) { + res->cc = 8; + return; + } + + break; + + //Check all tokens 3 chars long + case 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; iwc=i+1; + break; + } + } + return; + } + } + + //Check for NCD or NSC + if ((!strcmp(token, "NCD")) || (!strcmp(token, "NSC"))) { + res->cc = 1; + return; + } + + //Check for TCU + if (!strcmp(token, "TCU")) { + res->cc = 7; + return; + } + + break; + + //Check all tokens 4 chars long + case 4: + + //Check if token is a modified weather condition + for(i=0; iwc=i+1; + return; + } + } + break; + } + } + + break; + + //Check all tokens 5 chars long + case 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->temp=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->temp); + + 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 if token is a modified weather condition + if ((token[0] == '+') || (token[0] == '-')) { + for(i=0; iwc=i+1; + return; + } + } + break; + } + } + } + break; + + //Check all tokens 6 chars long + case 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; icc=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->temp = 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->temp); + + return; + } + } + + break; + + //Check all tokens 7 chars long + case 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->temp = -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->temp); + + 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; + } + + break; + + //Check all tokens 8 chars long + case 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; + } + + default: + + //printf("token : %s\n", token); + break; } - } - - //Check for NCD or NSC - if ((!strcmp(token, "NCD")) || (!strcmp(token, "NSC"))) { - res->cc = 1; - return; - } +} - //Check for TCU - if (!strcmp(token, "TCU")) { - res->cc = 7; - return; - } - - break; - - //Check all tokens 4 chars long - case 4: - - //Check if token is a modified weather condition - for(i=0; iwc=i+1; - return; - } - } - break; - } - } +static void parse_weather(PWEATHER *res, const char *data) +{ + char s_tmp[256]; + const char delim[] = " "; - break; + memset(res, 0, sizeof(PWEATHER)); - //Check all tokens 5 chars long - case 5: + //Divide time stamp and metar data + if (sscanf(data, "%[^'\n']\n%[^'\n']", res->lastupd, s_tmp) == 2) { - //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); + //Process all tokens + char *p_tok = NULL; + char *p_save = NULL; - //4th and 5th digits gives the dew point temperature - res->dew=atoi(&token[3]); + if ((strtok_r(s_tmp, delim, &p_save)) != NULL) { - //Compute humidity - res->hmid = rel_humidity(res->dew, res->tmpC); + //Jump first token, must be icao + p_tok = strtok_r(NULL, delim, &p_save); - //Convert to Fahrenheit (faster here than in conky.c) - res->tmpF = (res->tmpC*9)/5 + 32; + do { - return; - } - } + parse_token(res, p_tok); + p_tok = strtok_r(NULL, delim, &p_save); - //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 if token is a modified weather condition - if ((token[0] == '+') || (token[0] == '-')) { - for(i=0; iwc=i+1; + } while (p_tok != NULL); + } return; - } - } - break; - } - } - } - break; - - //Check all tokens 6 chars long - case 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; icc=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; + else { + return; } - 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; +void fetch_weather_info(location *curloc) +{ + CURL *curl = NULL; + CURLcode res; + + // curl temps + struct MemoryStruct chunk; + + chunk.memory = NULL; + chunk.size = 0; + + curl = curl_easy_init(); + if (curl) { + curl_easy_setopt(curl, CURLOPT_URL, curloc->uri); + curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 1); + curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, WriteMemoryCallback); + 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) { + timed_thread_lock(curloc->p_timed_thread); + parse_weather(&curloc->data, chunk.memory); + timed_thread_unlock(curloc->p_timed_thread); + free(chunk.memory); + } else { + ERR("No data from server"); + } - return; + curl_easy_cleanup(curl); } - } - - break; - - //Check all tokens 7 chars long - case 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; +void *weather_thread(void *) __attribute__((noreturn)); - return; - } +void init_thread(location *curloc, int interval) +{ + curloc->p_timed_thread = + timed_thread_create(&weather_thread, + (void *)curloc, interval * 1000000); + if (!curloc->p_timed_thread) { + ERR("Error creating weather timed thread"); } - } - - //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; + timed_thread_register(curloc->p_timed_thread, + &curloc->p_timed_thread); + if (timed_thread_run(curloc->p_timed_thread)) { + ERR("Error running weather timed thread"); } - if (i==7) return; - } - - break; - - //Check all tokens 8 chars long - case 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; - } - - default: - - //printf("token : %s\n", token); - break; - } } -static inline PWEATHER *parse_weather(const char *data) + +void process_weather_info(char *p, int p_max_size, char *uri, char *data_type, int interval) { - 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 ((strtok_r(s_tmp, delim, &p_save)) != NULL) { - - //Jump first token, must be icao - p_tok = strtok_r(NULL, delim, &p_save); - - do { - - parse_token(res, p_tok); - p_tok = strtok_r(NULL, delim, &p_save); - - } while (p_tok != NULL); - } - return res; - } - else { - return NULL; - } + static const char *wc[] = { + "", "drizzle", "rain", "hail", "soft hail", + "snow", "snow grains", "fog", "haze", "smoke", + "mist", "dust", "sand", "funnel cloud tornado", + "dust/sand", "squall", "sand storm", "dust storm" + }; + + location *curloc = find_location(uri); + if (!curloc->p_timed_thread) init_thread(curloc, interval); + + + timed_thread_lock(curloc->p_timed_thread); + if (strcmp(data_type, "last_update") == EQUAL) { + strncpy(p, curloc->data.lastupd, p_max_size); + } else if (strcmp(data_type, "temperature") == EQUAL) { + temp_print(p, p_max_size, curloc->data.temp, TEMP_CELSIUS); + } else if (strcmp(data_type, "cloud_cover") == EQUAL) { + if (curloc->data.cc == 0) { + strncpy(p, "", p_max_size); + } else if (curloc->data.cc < 3) { + strncpy(p, "clear", p_max_size); + } else if (curloc->data.cc < 5) { + strncpy(p, "partly cloudy", p_max_size); + } else if (curloc->data.cc == 5) { + strncpy(p, "cloudy", p_max_size); + } else if (curloc->data.cc == 6) { + strncpy(p, "overcast", p_max_size); + } else if (curloc->data.cc == 7) { + strncpy(p, "towering cumulus", p_max_size); + } else { + strncpy(p, "cumulonimbus", p_max_size); + } + } else if (strcmp(data_type, "pressure") == EQUAL) { + snprintf(p, p_max_size, "%d", curloc->data.bar); + } else if (strcmp(data_type, "wind_speed") == EQUAL) { + snprintf(p, p_max_size, "%d", curloc->data.wind_s); + } else if (strcmp(data_type, "wind_dir") == EQUAL) { + if ((curloc->data.wind_d >= 349) || (curloc->data.wind_d < 12)) { + strncpy(p, "N", p_max_size); + } else if (curloc->data.wind_d < 33) { + strncpy(p, "NNE", p_max_size); + } else if (curloc->data.wind_d < 57) { + strncpy(p, "NE", p_max_size); + } else if (curloc->data.wind_d < 79) { + strncpy(p, "ENE", p_max_size); + } else if (curloc->data.wind_d < 102) { + strncpy(p, "E", p_max_size); + } else if (curloc->data.wind_d < 124) { + strncpy(p, "ESE", p_max_size); + } else if (curloc->data.wind_d < 147) { + strncpy(p, "SE", p_max_size); + } else if (curloc->data.wind_d < 169) { + strncpy(p, "SSE", p_max_size); + } else if (curloc->data.wind_d < 192) { + strncpy(p, "S", p_max_size); + } else if (curloc->data.wind_d < 214) { + strncpy(p, "SSW", p_max_size); + } else if (curloc->data.wind_d < 237) { + strncpy(p, "SW", p_max_size); + } else if (curloc->data.wind_d < 259) { + strncpy(p, "WSW", p_max_size); + } else if (curloc->data.wind_d < 282) { + strncpy(p, "W", p_max_size); + } else if (curloc->data.wind_d < 304) { + strncpy(p, "WNW", p_max_size); + } else if (curloc->data.wind_d < 327) { + strncpy(p, "NW", p_max_size); + } else if (curloc->data.wind_d < 349) { + strncpy(p, "NNW", p_max_size); + }; + } else if (strcmp(data_type, "wind_dir_DEG") == EQUAL) { + snprintf(p, p_max_size, "%d", curloc->data.wind_d); + + } else if (strcmp(data_type, "humidity") == EQUAL) { + snprintf(p, p_max_size, "%d", curloc->data.hmid); + } else if (strcmp(data_type, "weather") == EQUAL) { + strncpy(p, wc[curloc->data.wc], p_max_size); + } + timed_thread_unlock(curloc->p_timed_thread); } -PWEATHER *get_weather_info(char *uri, int delay) +void *weather_thread(void *arg) { - 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; + location *curloc = (location*)arg; + + while (1) { + fetch_weather_info(curloc); + if (timed_thread_test(curloc->p_timed_thread, 0)) { + timed_thread_exit(curloc->p_timed_thread); + } + } + /* never reached */ } + diff --git a/src/weather.h b/src/weather.h index 2ec24c5..ff2d687 100644 --- a/src/weather.h +++ b/src/weather.h @@ -31,8 +31,7 @@ /* WEATHER data */ typedef struct PWEATHER_ { char lastupd[17]; - int tmpC; - int tmpF; + int temp; int dew; int cc; int bar; @@ -43,8 +42,8 @@ typedef struct PWEATHER_ { } PWEATHER; /* Prototypes */ -PWEATHER *get_weather_info(char *uri, int delay); void init_weather_info(void); void free_weather_info(void); +void process_weather_info(char *p, int p_max_size, char *uri, char *data_type, int interval); #endif /*WEATHER_H_*/