Like this...
post39289.html#p39289
-
Posts: 604
- Joined: 27 Feb 2009
-
Posts: 43
- Joined: 25 Apr 2010
That's actually more weather information than I want to display (in part for space issues), but I might like to know/figure out how to modify the weather script so that it pulls an evening forecast (if possible) and display day information, something like this:
[Example:]
{sky condition icon} Currently: (current conditions)
{sky condition icon} Tonight: (forecast conditions, chance of precipitation perhaps, forecast overnight low)
{sky condition icon} Tomorrow: (forecast conditions, chance of precipitation, forecast high)
{sky condition icon} Following Day: (forecast conditions, chance of precipitation, forecast high)
[/Example:]
I got the script I use from a link posted by rokytnji and spent parts of several days getting it to its current point. But it may not be the best script for what I want to do, so I guess I may need to check out one of the other scripts created by the same person and then see if I can cut it down to what I want. I do only want to run one instance of Conky, if possible.
[Example:]
{sky condition icon} Currently: (current conditions)
{sky condition icon} Tonight: (forecast conditions, chance of precipitation perhaps, forecast overnight low)
{sky condition icon} Tomorrow: (forecast conditions, chance of precipitation, forecast high)
{sky condition icon} Following Day: (forecast conditions, chance of precipitation, forecast high)
[/Example:]
I got the script I use from a link posted by rokytnji and spent parts of several days getting it to its current point. But it may not be the best script for what I want to do, so I guess I may need to check out one of the other scripts created by the same person and then see if I can cut it down to what I want. I do only want to run one instance of Conky, if possible.
-
Posts: 1,062
- Joined: 20 Jan 2010
#18
@thriftee, from where does that weather reports in conky come from? I was reading through it and found I was hearing a voice in my head from the weather reports off of the marine radio. I began reading it with all the pauses and tone changes just the same as if I were listening in the boat.
-
Posts: 43
WaltH - Joined: 25 Apr 2010
#19
It's close! I even managed to incorporate an image into the display. However, I have this annoying dash displaying in the forecast for tonight, and I can't see where it is coming from. Here is the relevant part of my .conkyrc:
And here is the weather script that is called (it pulls ten days of information, but I only wanted three):
And finally, here is a screenshot of what I am talking about:
Any thoughts? Thanks.
Code: Select all
${color8}${font Cantarell:Bold:size=12}Boise Weather ${hr 2}${execi 600 bash $HOME/1a_accuweather_conkyweather_font/1a}
${color3}${font conkyweather:size=30}${execi 600 sed -n '2p' ~/1a_accuweather_conkyweather_font/curr_cond}${color8}${font Cantarell:Bold:size=10}${goto 75}${voffset -30}CURRENTLY: ${execpi 600 sed -n '4p' $HOME/1a_accuweather_conkyweather_font/curr_cond}°F
${goto 75}${execpi 600 sed -n '3p' $HOME/1a_accuweather_conkyweather_font/curr_cond|fold -w30}
${color3}${font conkyweather:size=30}${execi 600 sed -n '2p' ~/1a_accuweather_conkyweather_font/tod_ton}${color8}${font Cantarell:Bold:size=10}${goto 75}${voffset -30}${execpi 600 sed -n '1p' $HOME/1a_accuweather_conkyweather_font/tod_ton}: ${execpi 600 sed -n '4p' $HOME/1a_accuweather_conkyweather_font/tod_ton}°F/${execpi 600 sed -n '5p' $HOME/1a_accuweather_conkyweather_font/tod_ton}°F
${goto 75}${execpi 600 sed -n '3p' $HOME/1a_accuweather_conkyweather_font/tod_ton|fold -w30}
${color3}${font conkyweather:size=30}${execi 600 sed -n '7p' ~/1a_accuweather_conkyweather_font/tod_ton}${color8}${font Cantarell:Bold:size=10}${goto 75}${voffset -30}${execpi 600 sed -n '6p' $HOME/1a_accuweather_conkyweather_font/tod_ton}: ${execpi 600 sed -n '9p' $HOME/1a_accuweather_conkyweather_font/tod_ton}°F/${execpi 600 sed -n '10p' $HOME/1a_accuweather_conkyweather_font/tod_ton}°F
${goto 75}${execpi 600 sed -n '8p' $HOME/1a_accuweather_conkyweather_font/tod_ton|fold -w30}
${color3}${font conkyweather:size=30}${execi 600 sed -n '12p' ~/1a_accuweather_conkyweather_font/tod_ton}${color8}${font Cantarell:Bold:size=10}${goto 75}${voffset -30}${execpi 600 sed -n '11p' $HOME/1a_accuweather_conkyweather_font/tod_ton}: ${execpi 600 sed -n '14p' $HOME/1a_accuweather_conkyweather_font/tod_ton}°F/${execpi 600 sed -n '15p' $HOME/1a_accuweather_conkyweather_font/tod_ton}°F
${goto 75}${execpi 600 sed -n '13p' $HOME/1a_accuweather_conkyweather_font/tod_ton|fold -w30}
Code: Select all
#!/bin/bash
#function: test_image
test_image () {
case $1 in
1)
echo a
;;
2|3)
echo b
;;
4|5)
echo c
;;
6)
echo d
;;
7)
echo e
;;
8)
echo f
;;
11)
echo 0
;;
12)
echo h
;;
13|14)
echo g
;;
15)
echo m
;;
16|17)
echo k
;;
18)
echo i
;;
19)
echo q
;;
20|21|23)
echo o
;;
22)
echo r
;;
24|31)
echo E
;;
25)
echo v
;;
26)
echo x
;;
29)
echo y
;;
30)
echo 5
;;
32)
echo 6
;;
33)
echo A
;;
34|35)
echo B
;;
36|37)
echo C
;;
38)
echo D
;;
39|40)
echo G
;;
41|42)
echo K
;;
43|44)
echo O
;;
*)
echo -
;;
esac
}
kill -STOP $(pidof conky)
killall wget
#put your Accuweather address here
#address="http://www.accuweather.com/en/si/ljubljana/299198/weather-forecast/299198"
address="http://www.accuweather.com/en/us/boise-id/83703/weather-forecast/328736"
loc_id=$(echo $address|sed 's/\/weather-forecast.*$//'|sed 's/^.*\///')
last_number=$(echo $address|sed 's/^.*\///')
curr_addr="$(echo $address|sed 's/weather-forecast.*$//')"current-weather/"$last_number"
wget -O $HOME/1a_accuweather_conkyweather_font/curr_cond_raw"$curr_addr"
addr1="$(echo $address|sed 's/weather-forecast.*$//')"daily-weather-forecast/"$last_number"
wget -O $HOME/1a_accuweather_conkyweather_font/tod_ton_raw"$addr1"
addr2="$addr1"?day=6
wget -O $HOME/1a_accuweather_conkyweather_font/last_days_raw"$addr2"
#current conditions
if [[ -s $HOME/1a_accuweather_conkyweather_font/curr_cond_raw ]]; then
sed -i '/detail-now/,/#details/!d' $HOME/1a_accuweather_conkyweather_font/curr_cond_raw
egrep -i '"cond"|icon i-|detail-tab-panel' $HOME/1a_accuweather_conkyweather_font/curr_cond_raw > $HOME/1a_accuweather_conkyweather_font/curr_cond
sed -i -e 's/^.*detail-tab-panel //g' -e 's/^.*icon i-//g' -e 's/"><\/div>.*$//g' $HOME/1a_accuweather_conkyweather_font/curr_cond
sed -i -e 's/^.*"cond">//g' -e 's/°/\n/g' -e 's/<\/span>.*"temp">/\n/g' -e 's/<.*>//g' $HOME/1a_accuweather_conkyweather_font/curr_cond
sed -i -e 's/">//g' -e 's/-->//g' -e 's/\r$//g' -e 's/ i-alarm.*$//g' -e 's/-[a-z].*$//g' $HOME/1a_accuweather_conkyweather_font/curr_cond
image=$(sed -n 2p $HOME/1a_accuweather_conkyweather_font/curr_cond)
sed -i 2s/$image/$(test_image $image)/ $HOME/1a_accuweather_conkyweather_font/curr_cond
fi
#First 5 days
if [[ -s $HOME/1a_accuweather_conkyweather_font/tod_ton_raw ]]; then
sed -i '/feed-tabs/,/\.feed-tabs/!d' $HOME/1a_accuweather_conkyweather_font/tod_ton_raw
egrep -i 'Early AM|Today|Tonight|Overnight|icon i-|cond|temp|Mon|Tue|Wed|Thu|Fri|Sat|Sun' $HOME/1a_accuweather_conkyweather_font/tod_ton_raw > $HOME/1a_accuweather_conkyweather_font/tod_ton
sed -i -e 's/^.*#">//g' -e 's/^.*icon i-//g' -e 's/^.*cond">//g' -e 's/^.*temp">//g' $HOME/1a_accuweather_conkyweather_font/tod_ton
sed -i -e 's/Lo<\/span> /\n/g' -e 's/<\/a>.*$//g' -e 's/"><.*$//g' -e 's/&#.*$//g' -e 's/teo//g' $HOME/1a_accuweather_conkyweather_font/tod_ton
sed -i -e 's/<span>.*$//g' -e 's/<\/span>//g' -e 's/\r$//g' -e 's/ i-alarm.*$//g' $HOME/1a_accuweather_conkyweather_font/tod_ton
sed -i -e 's/Early AM/EARLY AM/' -e 's/Today/TODAY/' -e 's/Tonight/TONIGHT/' -e 's/Overnight/OVERNIGHT/' -e 's/Mon$/MONDAY/' -e 's/Tue$/TUESDAY/' -e 's/Wed$/WEDNESDAY/' -e 's/Thu$/THURSDAY/' -e 's/Fri$/FRIDAY/' -e 's/Sat$/SATURDAY/' -e 's/Sun$/SUNDAY/' -e 's/-[a-z]$//g' $HOME/1a_accuweather_conkyweather_font/tod_ton
time=$(sed -n 1p $HOME/1a_accuweather_conkyweather_font/tod_ton)
image=$(sed -n 2p $HOME/1a_accuweather_conkyweather_font/tod_ton)
if [[ $time == TODAY ]]; then
sed -i 2s/$image/$(test_image $image)/ $HOME/1a_accuweather_conkyweather_font/tod_ton
elif [[ $time == TONIGHT || $time == OVERNIGHT || $time =="EARLY AM" ]]; then
sed -i 2s/$image/$(test_image $image)/ $HOME/1a_accuweather_conkyweather_font/tod_ton
sed -i 3a- $HOME/1a_accuweather_conkyweather_font/tod_ton
fi
for (( i=7; i<=22; i+=5 ))
do
image=$(sed -n"${i}"p $HOME/1a_accuweather_conkyweather_font/tod_ton)
sed -i ${i}s/$image/$(test_image $image)/ $HOME/1a_accuweather_conkyweather_font/tod_ton
done
fi
#Next 5 days
if [[ -s $HOME/1a_accuweather_conkyweather_font/last_days_raw ]]; then
sed -i '/feed-tabs/,/\.feed-tabs/!d' $HOME/1a_accuweather_conkyweather_font/last_days_raw
egrep -i 'icon i-|cond|temp|Mon|Tue|Wed|Thu|Fri|Sat|Sun' $HOME/1a_accuweather_conkyweather_font/last_days_raw > $HOME/1a_accuweather_conkyweather_font/last_days
sed -i -e 's/^.*#">//g' -e 's/^.*icon i-//g' -e 's/^.*cond">//g' -e 's/^.*temp">//g' $HOME/1a_accuweather_conkyweather_font/last_days
sed -i -e 's/Lo<\/span> /\n/g' -e 's/<\/a>.*$//g' -e 's/"><.*$//g' -e 's/&#.*$//g' -e 's/teo//g' $HOME/1a_accuweather_conkyweather_font/last_days
sed -i -e 's/<span>.*$//g' -e 's/<\/span>//g' -e 's/\r$//g' -e 's/ i-alarm.*$//g' $HOME/1a_accuweather_conkyweather_font/last_days
sed -i -e 's/Mon$/MONDAY/' -e 's/Tue$/TUESDAY/' -e 's/Wed$/WEDNESDAY/' -e 's/Thu$/THURSDAY/' -e 's/Fri$/FRIDAY/' -e 's/Sat$/SATURDAY/' -e 's/Sun$/SUNDAY/' -e 's/-[a-z]$//g' $HOME/1a_accuweather_conkyweather_font/last_days
for (( i=2; i<=22; i+=5 ))
do
image=$(sed -n"${i}"p $HOME/1a_accuweather_conkyweather_font/last_days)
sed -i ${i}s/$image/$(test_image $image)/ $HOME/1a_accuweather_conkyweather_font/last_days
done
fi
kill -CONT $(pidof conky)
Any thoughts? Thanks.
-
Posts: 43
- Joined: 25 Apr 2010
#20
Okay, now I feel a bit stupid. I just realized the dash is because there is no forecast high temperature for today to display now that it is evening. __{{emoticon}}__ However, it would be nice if it did not display that, so if anyone has ideas on how to tweak the script to keep the dash (i.e., blank high temperature) from displaying after, say 6:00 p.m. it would be much appreciated.
Also, is there a way to make the display semi-transparent rather than fully transparent in IceWM? I know there are some lua scripts that might work, but after spending several days messing just with the scripts I've already fooled around with, I think I'd like another approach if there is one. Thanks.
Also, is there a way to make the display semi-transparent rather than fully transparent in IceWM? I know there are some lua scripts that might work, but after spending several days messing just with the scripts I've already fooled around with, I think I'd like another approach if there is one. Thanks.
Last edited by WaltH on 20 Aug 2015, 04:10, edited 1 time in total.
-
Posts: 604
- Joined: 27 Feb 2009
#21
I got a job a few months ago, and so I've been real busy and exhausted when I get home every night. After fighting fires and writing code 12 hrs a day, there just isn't much left in me, but I needed the money...
Walt, I don't see any dash in your conky, but my screen is small, my brain is dead and my eyes are worn out, so its quite possible its there, LOL.
Well, mine is made out of the NWS 7 day text forecast, so, yes, that is just like what they read, but then I run the text through a script full of scan/replace and reformatting code, turning it into one long string per section of forecast, and then substitute phrases and words into shorter ways of saying things and once done, I reformat it back to XX width wise, wrapping it to fix my conky window. Its actually around 1/2 the size of the text I start with, and just as readable.Dave wrote:@thriftee, from where does that weather reports in conky come from? I was reading through it and found I was hearing a voice in my head from the weather reports off of the marine radio. I began reading it with all the pauses and tone changes just the same as if I were listening in the boat.
I got a job a few months ago, and so I've been real busy and exhausted when I get home every night. After fighting fires and writing code 12 hrs a day, there just isn't much left in me, but I needed the money...
Walt, I don't see any dash in your conky, but my screen is small, my brain is dead and my eyes are worn out, so its quite possible its there, LOL.
-
Posts: 43
- Joined: 25 Apr 2010
#22
I figured out why it's there. It's nighttime, but the script is still looking for the forecast high temperature though there isn't one and won't be one until after midnight. While I suspect there may be a way to modify the script so it leaves that blank after the high temperature for the day has come and gone, that knowledge is a bit above my pay grade. __{{emoticon}}__thriftee wrote:Walt, I don't see any dash in your conky, but my screen is small, my brain is dead and my eyes are worn out, so its quite possible its there, LOL.
-
Posts: 604
- Joined: 27 Feb 2009
#23
I don't pretend to be much of a coder on linux, and given that your conky is doing pretty well, this probably won't help you much, but maybe it will help someone else coming along another day...
I forget where I found that current forecast script, but its not my code, I just massaged it to get a one liner of current conditions.
The 7 day translation is something I wrote. Its not perfect, but it leaves a nice trail of breadcrumbs for debugging and works well.
Here is the relevant code from mine...
NOTE: KORD is the code for OHare Airport, which is nearby, and il/ilz014.txt is the name of the file the NWS strores the text version of the zone forecast under
getweatherc.sh
getweather7d.sh - Get NWS 7 day text forecast and massages it into abbreviated text 80 wide, with a maximum of 26 lines
I forget where I found that current forecast script, but its not my code, I just massaged it to get a one liner of current conditions.
The 7 day translation is something I wrote. Its not perfect, but it leaves a nice trail of breadcrumbs for debugging and works well.
Here is the relevant code from mine...
Code: Select all
#.conkyrc
# Update interval in seconds
update_interval 5
text_buffer_size 6000
max_specials 600
# set to yes if you want Conky to be forked in the background
background yes
short_units yes
cpu_avg_samples 2
net_avg_samples 2
out_to_console no
# X font when Xft is disabled, you can pick one with program xfontsel
#font 7x12
#font 6x10
#font 7x13
font 8x12
#font 7x12
#font *mintsmild.se*
#font -*-*-*-*-*-*-34-*-*-*-*-*-*-*
#font -artwiz-snap-normal-r-normal-*-*-100-*-*-p-*-iso8859-1
# Use Xft?
use_xft yes
# Xft font when Xft is enabled
xftfont Sans:size=10
# Create own window instead of using desktop (required in nautilus, pcmanfm and rox desktops)
own_window yes
own_window_type desktop
own_window_transparent yes
own_window_hints undecorated,sticky,skip_taskbar
# Text alpha when using Xft
xftalpha 0.8
#on_bottom no
# mail spool
#mail_spool $MAIL
# Use double buffering (reduces flicker, may not work for everyone)
double_buffer yes
# Minimum size of text area
minimum_size 445 845
maximum_width 545
# Gap between borders of screen and text
# x = distance from right edge
# y = distance from top edge
gap_x 18
gap_y 2
# Draw shades?
draw_shades no
# Draw outlines?
draw_outline no
# Draw borders around text
draw_borders no
# Stippled borders?
stippled_borders 0
# border margins
#border_margin 10
# border width
border_width 2
# color scheme
color0 black
color1 red
color2 green
color3 yellow
color4 blue
color5 magenta
color6 cyan
color7 white
# hot pink
#color8 #FF078B
# flourecent orange
#color9 #FF9C07
# Default colors and also border colors
default_color white
default_shade_color white
default_outline_color white
# Text alignment, other possible values are commented
#alignment top_left
alignment top_right
#alignment bottom_left
#alignment bottom_right
# Add spaces to keep things from moving about? This only affects certain objects.
use_spacer right
# Subtract file system buffers from used memory?
no_buffers yes
# set to yes if you want all text to be in uppercase
uppercase no
# boinc (seti) dir
# seti_dir /opt/seti
# stuff after 'TEXT' will be formatted on screen
TEXT
###${font Sans:size=10}${color2}Host:
${font Sans:size=16}${color #FF078B}${nodename} ${font Sans:size=10}${alignr 39}${color2}Date: ${color}${time %c}
${color2}CpuAvg: ${color}${freq_g}Ghz ${machine} - ${color}${cpu}% ${color2}System/kernel: ${color}$sysname $kernel
${color2} Cpu 1: ${color}${cpu cpu1}% \
${if_match ${cpu cpu1} <= 50}\
${color green}${cpubar cpu1 9}\
${else}\
${if_match ${cpu cpu1} <= 80}\
${color orange}${cpubar cpu1 9}\
${else}\
${color red}${cpubar cpu1 9}\
${endif}\
${endif}
${color2} Cpu 2: ${color}${cpu cpu2}% \
${if_match ${cpu cpu2} <= 50}\
${color green}${cpubar cpu2 9}\
${else}\
${if_match ${cpu cpu2} <= 80}\
${color orange}${cpubar cpu2 9}\
${else}\
${color red}${cpubar cpu2 9}\
${endif}\
${endif}
${color2}Bat: ${color}${battery BAT0}\
${if_match"$battery_short"<"D"}\
${if_match ${battery_percent BAT0} <= 40}\
${color red} ${battery_bar 9 BAT0}${color2}\
${else}\
${if_match ${battery_percent BAT0} <= 80}\
${color orange} ${battery_bar 9 BAT0}${color2}\
${else}\
${color green} ${battery_bar 9 BAT0}\
${endif}\
${endif}\
${else}\
${if_match ${battery_percent BAT0} <= 40}\
${blink ${color red} ${battery_bar 9 BAT0} }${color2}\
${else}\
${if_match ${battery_percent BAT0} <= 80}\
${color orange} ${battery_bar 9 BAT0}${color2}\
${else}\
${color green} ${battery_bar 9 BAT0}\
${endif}\
${endif}\
${endif}
${color2}Ram : ${color}$mem${color}/${color}$memmax ${color}- $memperc% \
${if_match ${memperc} <= 50}\
${color green}${membar 9}\
${else}\
${if_match ${memperc} <= 80}\
${color orange}${membar 9}\
${else}\
${color red}${membar 9}\
${endif}\
${endif}
${color2}Swap: ${color}$swap${color}/${color}$swapmax ${color}- ${color}$swapperc% \
${if_match ${swapperc} <= 25}\
${color green}${swapbar 9}\
${else}\
${if_match ${swapperc} <= 60}\
${color orange}${swapbar 9}\
${else}\
${color red}${swapbar 9}\
${endif}\
${endif}
${color2}Root:${color} ${fs_free /}Free ${color}= ${fs_free_perc /}% \
${if_match ${fs_free_perc} <= 25}\
${color red}${fs_bar 9}\
${else}\
${if_match ${fs_free_perc} <= 50}\
${color orange}${fs_bar 9}\
${else}\
${color green}${fs_bar 9}\
${endif}\
${endif}
${color2}Wireless: ${color}${wireless_essid wlan0} ${color2}IP:${color} ${addr wlan0} ${color2}spd: ${color} ${wireless_bitrate wlan0} ${color2}strength: ${color3} ${wireless_link_bar 9 wlan0}
${color2}Processes: ${color}$processes ${color2}Running: ${color}$running_processes ${color2}Uptime: ${color}$uptime ${color2}wlan0 Up/Dn ${color}${upspeed wlan0}${color2}/${color}${downspeed wlan0}
${color2}Name PID CPU% MEM% ${color2}eth0 Up/Dn ${color}${upspeed eth0}${color2}/${color}${downspeed eth0}
${color} ${top name 1} ${top pid 1} ${top cpu 1} ${top mem 1}
${color} ${top name 2} ${top pid 2} ${top cpu 2} ${top mem 2}
${color} ${top name 3} ${top pid 3} ${top cpu 3} ${top mem 3}
${color} ${top name 4} ${top pid 4} ${top cpu 4} ${top mem 4}
${color2}News Headlines:
${color}${execi 60 conky-rss.sh http://feeds.abcnews.com/abcnews/topstories 9 2}
${font Sans:size=10}${color2}NWS Current Weather and Forecast:
${font Sans:size=10}${color3}${execi 120 getweatherc.sh KORD}
${font Sans:size=8}${color}${execi 600 getweather7d.sh il/ilz014.txt}
${font Ubuntu Mono:bold:size=15}${color2} ${time %B} ${time %Y}
${color3}${font Ubuntu Mono:bold:size=15}${execpi 300 DJS=`date +%_d`; cal | sed '1d' | sed '2s/^/\${color}/' | sed 's/^/ /g' | sed s/"\(^\|[^0-9]\)$DJS"'\b'/'\1${color2}'"$DJS"'$color'/}
getweatherc.sh
Code: Select all
#!/bin/bash
# getweatherc.sh - - Gets and returns one line current conditions for weather station code passed as parm1
# usage: getweatherc.sh KORD
#
# Requires: wget, sed
station="$1.xml"
wdir='/tmp/weather'
update_xml() {
if [ ! -e"$station" ]; then
wget -q http://w1.weather.gov/xml/current_obs/${station}
[ -e"$station" ] && touch"${station}"
else
# dtime: time the .xml file was downloaded
# otime: time the weather data was observed
# ctime: current time (time this script is being run)
dtime=$(stat -c %Y $station)
otime=$(date -d"$utime" +%s)
ctime=$(date +%s)
if (("$otime" + 4507 <"$ctime" )); then
if (("$dtime" + 307 <"$ctime" )); then
wget -q -O"$station" http://w1.weather.gov/xml/current_obs/${station}
[ -e"$station" ] && touch"${station}"
fi
fi
fi
}
from_xml() { xmllint -xpath"//$1" - <<<"$xml" | sed 's/<[^>]*>//g'; }
[ -d"$wdir" ] || mkdir -p"$wdir"
cd"$wdir" || exit 1
xml=''
[ -r $station ] && xml="$(< $station)"
( update_xml >/dev/null 2>&1 ) &
if [ -n"$xml" ]; then
location=$(from_xml"location")
# if we just want the city the location is in
#locationx=$(from_xml"location")
#location="$(echo"$locationx" | cut -f1 -d",")"
utime=$(from_xml"observation_time_rfc822")
otime=$(date -d"$utime" '+%a %b %e %R')
#date +"%Y/%m/%d %H:%M"
#Invoking date with no format argument is equivalent to invoking `date '+%a %b %e %H:%M:%S %Z %Y''.
weather=$(from_xml"weather")
temperature=$(from_xml"temp_f")
humid=$(from_xml"relative_humidity")
wind_dir=$(from_xml"wind_dir")
case"$wind_dir" in
"North") wind_dir="N" ;;
"South") wind_dir="S" ;;
"East") wind_dir="E" ;;
"West") wind_dir="W" ;;
"Northwest") wind_dir="NW" ;;
"Northeast") wind_dir="NE" ;;
"Southwest") wind_dir="SW" ;;
"Southeast") wind_dir="SE" ;;
esac
wind_speed=$(from_xml"wind_kt")
baro_pressure=$(from_xml"pressure_in")
### echo"$location"
printf '%s, %s %s F, wind %s %s kt in %s, NWS station %s\n'"$otime""$weather""$temperature""$wind_dir""$wind_speed""$location""$1"
### echo"$location"
### printf 'Weather: %s %s°F\n'"$weather""$temperature"
### printf 'Barometric Pressure: %s inches\n'"$baro_pressure"
### printf 'Wind: %s at %s knots\n'"$wind_dir""$wind_speed"
### printf 'Humidity: %s%%\n'"$humid"
### echo"Updated: $(date -d"$utime" 2>/dev/null )"
else
echo"ERROR: No weather data available for $1..."
fi
Code: Select all
#!/bin/bash
# getweather7d - gets weather forecast text file
# usage: getweather7d.sh il/ilz014.txt
# files are stored by state, so need to pass combined state and filename
# delete first 11 lines and last 2 lines to get actual forecast text
#
# Requires: curl, tr, fold, sed
#
if ["$1" ="" ]; then
echo"ERROR, usage: getweather7d.sh il/ilz014.txt"
else
curl_retryn=0
curl -s http://weather.noaa.gov/pub/data/forecasts/zone/$1 > ~/.getweather7d.tmp.txt
if [ $? -ne 0 ]; then
while [ curl_retryn -le 3 ]
do
sleep 10
curl_retryn=`expr $curl_retryn + 1`
curl -s http://weather.noaa.gov/pub/data/forecasts/zone/$1 > ~/.getweather7d.tmp.txt
if [ $? -ne 0 ]; then
continue
fi
curl_retryn=0
break
done
fi
if [ $curl_retryn -ne 0 ]; then
echo"ERROR, getweather7d.sh curl failed to get weather for $1"
else
# ~/.getweather7d.tmp.txt now contains text of 7 day forecast, remove 1st 2 lines and 1st 11 lines,
# delete 1st char of 1st line
cat ~/.getweather7d.tmp.txt | sed '$ d' | sed '$ d' | sed '1,11 d' | sed -e '1s/^.//' > ~/.getweather7d.tmp2.txt
# lines are wrapped at xx chars, so need to unwrap and then rewrap at yy chars
# change all newline 0a characters into and all . to b
tr '\n' 'a' < ~/.getweather7d.tmp2.txt > ~/.getweather7d.tmp3.txt
tr '.' 'b' < ~/.getweather7d.tmp3.txt > ~/.getweather7d.tmp4.txt
# ab combos are real newlines, and change all ... to -
cat ~/.getweather7d.tmp4.txt | sed -e"s/ab/\n/g" | sed -e"s/bbb/-/g" > ~/.getweather7d.tmp5.txt
# change b back to. and make a into spaces
tr 'b' '.' < ~/.getweather7d.tmp5.txt > ~/.getweather7d.tmp6.txt
tr 'a' ' ' < ~/.getweather7d.tmp6.txt > ~/.getweather7d.tmp7.txt
cat ~/.getweather7d.tmp7.txt | sed -e"s/^/--/g" | sed -e"s/ PERCENT/%/g" | sed -e"s/TEMPERATURES/TEMPS/g" \
| sed -e"s/BELOW ZERO/BELOW/g" | sed -e"s/ABOVE ZERO/ABOVE/g" | sed -e"s/ ABOVE//g" | sed -e"s/ ZERO/ 0/g" \
| sed -e"s/SUBURBS/BURBS/g" | sed -e"s/DOWNTOWN/CITY/g" \
| sed -e"s/MPH WITH GUSTS UP/MPH, GUSTS/g" | sed -e"s/GUSTS UP TO/GUSTS TO/g" | sed -e"s/CHILLS/CHILL/g" \
| sed -e"s/WINDS/WIND/g" | sed -e"s/LOWS/LOW/g" | sed -e"s/HIGHS/HIGH/g" | sed -e"s/BITTERLY/BITTER/g" \
| sed -e"s/NUMEROUS SNOW SHOWERS/SNOW/g" | sed -e"s/SNOW SHOWERS/SNOW/g" | sed -e"s/RAIN SHOWERS/RAIN/g" \
| sed -e"s/ACCUMULATION/ACCUM/g" \
| sed -e"s/ADVISORY IN EFFECT FROM/ADVISORY FROM/g" \
| sed -e"s/PRECIPITATION/PRECIP/g" > ~/.getweather7d.tmp8.txt
# to limit number of forecast day/night sections, count each section as a line before wrapping, typically 15 max
cat ~/.getweather7d.tmp8.txt | sed -e '15,$d' > ~/.getweather7d.tmp9.txt
# wrap text for 80 char wide display, limit to 26 lines of output
fold -s -w 80 ~/.getweather7d.tmp9.txt | sed -e '26,$d' > ~/.getweather7d.tmp10.txt
# print lines to std output, conky will get result and display
cat ~/.getweather7d.tmp10.txt
fi
fi