Since there are libraries for many languages to handle xml code parsing, I was wondering if any xml help existed for shell programs in Linux and ran across this -
http://xml-coreutils.sourceforge.net/
It's a set of utilities aimed at emulating the standard shell text tools like sed, tr, cat, printf, find, etc... but specifically for xml.
I compiled xml-printf which can be used to capture the content between tags and made a tray icon program for weather.
Tweather takes information from rss.accuweather.com by zip code and displays the current weather icon in the tray. When the mouse is moved over the icon, current conditions are displayed and the forecast for tomorrow. A left-click of the icon refreshes the data and a right-click quits the program.
You'll need to edit the zip code at the top of the script for the zipcode you want to monitor.
Tweather requires Technosaurus' sit program found here-
http://www.murga-linux.com/puppy/viewto ... 1&start=70
and xml-printf which is in the attached xml-printf.tar.gz file. EDIT: see next post with a much smaller version kindly compiled by Vovchik
Probably best used by linking the tweather script to the /root/Startup folder so that it's available at the start.
Cheers,
s
Code: Select all
#!/bin/sh -a
# tweather tray icon weather
# Requires Technosaurus' sit program and xml-printf
# Seaside December 29, 2012
# Left-click refresh Right-click quit
# Place zip code below
refresh() {
zipcode='10012' # <<< zipcode here
loc='http://rss.accuweather.com/rss/liveweather_rss.asp?locCode='"$zipcode"''
wget -O /tmp/tweather $loc
w=`xml-printf '%s\n' /tmp/tweather :/rss/channel/item/description`
i=o
while read line; do
array[$((++i))]=$line
case $i in
1) CURRENT=${line%%<*} CURRENTI=${line#*=} CURRENTI=${CURRENTI/>/} ; wget -O /tmp/currenti ${CURRENTI//\"/} ;;
2) RANGE=${line%%<*} ;;
3) TOMORROW=${line%%<*} ;;
*) ;;
esac
done <<<"$w"
echo "$CURRENT
$RANGE
-------------------------------------------------------------------
Tomorrow: $TOMORROW" >/tmp/tweather-tip
}
export -f refresh
refresh
sit /tmp/currenti /tmp/tweather-tip refresh "kill $( </tmp/tweatherpid)" &
tweatherPID=$!
echo $tweatherPID >/tmp/tweatherpid