).| The Following User Says Thank You to Mentalist Traceur For This Useful Post: | ||
| The Following User Says Thank You to Mentalist Traceur For This Useful Post: | ||
Current: -3 Conditions: Light Snow High: -2 Low: -3 Image: /tmp/ywtemp.png
Current: -3 Conditions: Light Snow High: -2 Low: -3 Image: /tmp/ywtemp.png
#!/bin/sh
#Arguments:
# 1 = Place id - from ukmo website
# 2 = output dir
url="http://www.metoffice.gov.uk/mobile/"
# Your default location here, take it from the Met Office mobile
# website.
id=${2-"XXXXXX"}
out=${3-"/tmp"}
post="forecastid=$id"
# Get info for day
wget --user-agent="" -q -t 1 -T 10 --post-data="$post" -O "$out/ywtemp.htm" "${url}5dayforecastdetail" || { exit 1; }
curday=`date "+%a %d %b %y"`
eval `awk '
BEGIN { use = 0 }
/.h2.'"$curday"'..h2./ { use = 1 }
use == 1 && /weathervalues/ { sub("^.*>Temperature: ","");
sub(" .*\\\(", " ");
sub(" .*$", "");
high=$1; low=$2; exit }
END { printf("high=\"%s\" low=\"%s\"", high, low)}' "$out/ywtemp.htm"
`
# Get info specific to time of day
curtime=`date +%H`00
if [ $curtime -lt 1200 ]; then
curtime=0900
elif [ $curtime -ge 1200 ] && [ $curtime -lt 1500 ]; then
curtime=1200
elif [ $curtime -ge 1500 ] && [ $curtime -lt 1800 ]; then
curtime=1500
elif [ $curtime -ge 1800 ] && [ $curtime -lt 2100 ]; then
curtime=1800
elif [ $curtime -gt 2100 ]; then
curtime=2100
fi
curday=`date "+%a %d %b %y" | sed 's/ /%20/g'`
post="forecastid=$id&detail=$curday"
wget --user-agent="" -q -t 1 -T 10 --post-data="$post" -O "$out/ywtemp.htm" "${url}5dayforecastdetail" || { exit 1; }
eval `awk '
BEGIN { use = 0 }
/Time: '$curtime'/ { use = 1 }
use == 1 && /img/ { sub("^.*src=", ""); sub(" alt.*$", ""); img=$0 }
use == 1 && /weathervalues/ {
sub("^.*weathervalues\">", "")
sub(" .*$", "")
sub("<br/>Temperature: ","\" temp=\"")
wx=$0
exit
}
END { printf("icon=\"%s\" conditions=\"%s\"", img, wx)}' "$out/ywtemp.htm"
`
wget --user-agent="" -q -t 1 -T 10 -O "$out/ywtemp.gif" "${url}${icon}" || { exit 1; }
echo "Current: "$temp
echo "Conditions: "$conditions
echo "High: "$high
echo "Low: "$low
echo "Image: $out/ywtemp.png"
| The Following User Says Thank You to skanky For This Useful Post: | ||
#!/bin/sh
#Arguments:
# 1 = Link to yahoo weather
# 2 = output dir
# 3 = Biggest weather code to consider
url=${1-"weather.yahooapis.com/forecastrss?w=455861&u=c"}
out=${2-"/tmp"}
big=${3-"47"}
let big="$big"+1
# ========sakya's translation========
# In order to work with QtLockscreen I need to, in the WORST case scenario:
# http://weather.yahoo.com/weather.yahooapis.com/forecastrss?w=455861&u=c?unit=c
# 1) Remove the 'http://weather.yahoo.com/'
# 2) Translate the appended '?unit=X' to '&u=X'
url=`echo "$url" | sed s/weather.yahoo.com\\\/// | sed 's/&u=[cf]//' | sed 's/?unit/\&u/'`
# the only problem is that now it requires the ?unit=c to recognize celcius, but for the qtlockscreen it is ok.
code="44d"
curr="0"
cond="Unknown"
high="0"
loww="0"
# Getting all the necessary info.
wget --user-agent="" -q -t 1 -T 10 -O "$out/ywtemp.xml" "$url" || { exit 1; }
# Now I have to find out the condition code in order to select the icon to download
code=`cat "$out/ywtemp.xml" | grep -o code=\".* -m 1 | sed s/code=\"// | sed s/\".*//`|| { exit 1; }
# I think that it is safe to translate odd codes to night and even codes to day. It is difficult to get each match on the site, there's nothing anywhere to look into. The weather developer API does not stabilish a correlation.
if [ "$code" -lt "$big" ]
then
# It is lower than the bigger known good weather code (47?), so, it isn't the unknown code 3200 or any other also unknown. Now the unknown icon are the 44d and 44n that are equal N/A:
if [ ` expr $code % 2 ` -eq 0 ]
then
code="$code""d";
else
code="$code""n";
fi
curr=`cat "$out/ywtemp.xml" | grep -o temp=\".* -m 1 | sed s/temp=\"// | sed s/\".*//` || { exit 1; }
cond=`cat "$out/ywtemp.xml" | grep -o text=\".* -m 1 | sed s/text=\"// | sed s/\".*//` || { exit 1; }
high=`cat "$out/ywtemp.xml" | grep -o high=\".* -m 1 | sed s/high=\"// | sed s/\".*//` || { exit 1; }
loww=`cat "$out/ywtemp.xml" | grep -o low=\".* -m 1 | sed s/low=\"// | sed s/\".*//` || { exit 1; }
else
code="44d";
fi
# Getting the icon...
wget --user-agent="" -q -t 1 -T 10 -O "$out/ywtemp.png" "l.yimg.com/os/mit/media/m/weather/images/icons/l/$code-100567.png" || { exit 1; }
echo "Current: $curr"
echo "Conditions: $cond"
echo "High: $high"
echo "Low: $loww"
echo "Image: $out/ywtemp.png"
#!/bin/sh
#Arguments:
# 1 = Link to yahoo weather
# 2 = output dir
# 3 = Biggest weather code to consider
url=${1-"weather.yahooapis.com/forecastrss?w=2122265&u=c?unit=c"}
out=${2-"/tmp"}
# ========sakya's translation========
# In order to work with QtLockscreen I need to, in the WORST case scenario:
# http://weather.yahoo.com/weather.yahooapis.com/forecastrss?w=455861&u=c?unit=c
# 1) Remove the 'http://weather.yahoo.com/'
# 2) Translate the appended '?unit=X' to '&u=X'
url=`echo "$url" | sed s/weather.yahoo.com\\\/// | sed 's/&u=[cf]//' | sed 's/?unit/\&u/'`
# the only problem is that now it requires the ?unit=c to recognize celcius, but for the qtlockscreen it is ok.
curr="0"
cond="Unknown"
high="0"
loww="0"
# Getting the XML and extracting the weather icon URL
wget --user-agent="" -q -t 1 -T 10 -O "$out/ywtemp.xml" "$url" || { exit 1; }
image=`cat "$out/ywtemp.xml" | grep "img src" | sed s'_<img src="__' | sed s'_"/><br />__'`|| { exit 1; }
#echo "$image"
# Setting weather conditions
curr=`cat "$out/ywtemp.xml" | grep -o temp=\".* -m 1 | sed s/temp=\"// | sed s/\".*//` || { exit 1; }
cond=`cat "$out/ywtemp.xml" | grep -o text=\".* -m 1 | sed s/text=\"// | sed s/\".*//` || { exit 1; }
high=`cat "$out/ywtemp.xml" | grep -o high=\".* -m 1 | sed s/high=\"// | sed s/\".*//` || { exit 1; }
loww=`cat "$out/ywtemp.xml" | grep -o low=\".* -m 1 | sed s/low=\"// | sed s/\".*//` || { exit 1; }
# Getting the icon...
# The icon has been changed to GIF by Yahoo, writing it with a PNG extension works.
wget --user-agent="" -q -t 1 -T 10 -O "$out/ywtemp.png" "$image" || { exit 1; }
echo "Current: $curr"
echo "Conditions: $cond"
echo "High: $high"
echo "Low: $loww"
echo "Image: $out/ywtemp.png"
