@@ -24,7 +24,7 @@ getWeather() {
24
24
local woeid=" $1 "
25
25
26
26
local api_output=$( getYahooXML " $woeid " )
27
- echo " $api_output " | xmlstarlet sel -N yweather=" http://xml.weather.yahoo.com/ns/rss/1.0" -t -m ' /rss /channel/item/yweather:condition' -v ' @code'
27
+ echo " $api_output " | xmlstarlet sel -N yweather=" http://xml.weather.yahoo.com/ns/rss/1.0" -t -m ' /query/results /channel/item/yweather:condition' -v ' @code'
28
28
}
29
29
30
30
# get WOEID uesed for as location by Yahoo
@@ -44,8 +44,7 @@ getYahooWOEID() {
44
44
# return: full xml-response
45
45
getYahooXML () {
46
46
local woeid=" $1 "
47
-
48
- local yahooWeather=$( wget -O - -q " http://weather.yahooapis.com/forecastrss?w=$woeid &u=c" )
47
+ local yahooWeather=$( wget -O - -q " https://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20weather.forecast%20where%20woeid%20=%20${woeid} &format=xml" )
49
48
echo " $yahooWeather "
50
49
}
51
50
@@ -55,7 +54,7 @@ getYahooXML() {
55
54
getSunrise () {
56
55
local api_output=" $1 "
57
56
58
- echo " $api_output " | xmlstarlet sel -N yweather=" http://xml.weather.yahoo.com/ns/rss/1.0" -t -m ' /rss /channel/yweather:astronomy' -v ' @sunrise'
57
+ echo " $api_output " | xmlstarlet sel -N yweather=" http://xml.weather.yahoo.com/ns/rss/1.0" -t -m ' /query/results /channel/yweather:astronomy' -v ' @sunrise'
59
58
}
60
59
61
60
# get date of sunset from yahoo
@@ -64,7 +63,7 @@ getSunrise() {
64
63
getSunset () {
65
64
local api_output=" $1 "
66
65
67
- echo " $api_output " | xmlstarlet sel -N yweather=" http://xml.weather.yahoo.com/ns/rss/1.0" -t -m ' /rss /channel/yweather:astronomy' -v ' @sunset'
66
+ echo " $api_output " | xmlstarlet sel -N yweather=" http://xml.weather.yahoo.com/ns/rss/1.0" -t -m ' /query/results /channel/yweather:astronomy' -v ' @sunset'
68
67
}
69
68
70
69
# map forecast-code to one of the icons
@@ -264,11 +263,11 @@ setImage() {
264
263
if [ " $PREVIEW " == " TRUE" ]; then
265
264
for i in {1..5}; do
266
265
# merge preview-icons with background-image
267
- local forecast=$( echo " $api_output " | xmlstarlet sel -N yweather=" http://xml.weather.yahoo.com/ns/rss/1.0" -t -m " /rss /channel/item/yweather:forecast[$i ]" -v ' @code' )
266
+ local forecast=$( echo " $api_output " | xmlstarlet sel -N yweather=" http://xml.weather.yahoo.com/ns/rss/1.0" -t -m " /query/results /channel/item/yweather:forecast[$i ]" -v ' @code' )
268
267
local icon=$( chooseForecastIcon " $forecast " )
269
268
local tmpicon=$( mktemp)
270
269
cp " /usr/share/izulu/$icon " " $tmpicon "
271
- local day=$( echo " $api_output " | xmlstarlet sel -N yweather=" http://xml.weather.yahoo.com/ns/rss/1.0" -t -m " /rss /channel/item/yweather:forecast[$i ]" -v ' @day' )
270
+ local day=$( echo " $api_output " | xmlstarlet sel -N yweather=" http://xml.weather.yahoo.com/ns/rss/1.0" -t -m " /query/results /channel/item/yweather:forecast[$i ]" -v ' @day' )
272
271
convert " $tmpicon " -gravity South -fill ' #c0bfbd' -font Helvetica -background ' #0000' -pointsize 16 -splice 0x24 -annotate +0+2 " $day " " $tmpicon "
273
272
274
273
# at least +20 y height to be above typical taskbar
@@ -277,7 +276,10 @@ setImage() {
277
276
fi
278
277
279
278
if [ " $TEMPERATURE " == " TRUE" ]; then
280
- local temperature=$( echo " $api_output " | xmlstarlet sel -N yweather=" http://xml.weather.yahoo.com/ns/rss/1.0" -t -m " /rss/channel/item/yweather:condition" -v ' @temp' )
279
+ local temperature=$( echo " $api_output " | xmlstarlet sel -N yweather=" http://xml.weather.yahoo.com/ns/rss/1.0" -t -m " /query/results/channel/item/yweather:condition" -v ' @temp' )
280
+ # yql is only giving us fahrenheit values, so we have to convert it into a sane unit
281
+ temperature=$( echo " ($temperature - 32) * 0.5556" | bc -l)
282
+ temperature=${temperature/ .*/ }
281
283
convert -gravity " $TEMPERATURE_GRAVITY " " $tmpimage " -font Helvetica -pointsize 36 -fill ' #c0bfbd' -background ' #0000' -annotate " $TEMPERATURE_MARGIN " " $temperature °C" " $tmpimage "
282
284
fi
283
285
@@ -506,16 +508,16 @@ getFlickrImage() {
506
508
getCurrentTime () {
507
509
local api_output=" $1 "
508
510
509
- local build_date=$( echo " $api_output " | xmlstarlet sel -t -m /rss /channel/lastBuildDate -v ' .' )
511
+ local build_date=$( echo " $api_output " | xmlstarlet sel -t -m /query/results /channel/lastBuildDate -v ' .' )
510
512
local build_time=$( echo $build_date | sed ' s/.*\(..:.....\).*/\1/' )
511
513
512
- # 12:20 pm hast to be caught and converted to 00:20 pm
513
- if [ " $( echo ${build_time: 6} ) " = " pm" ] && [ " $( echo ${build_time: 0: 2} ) " = " 12" ]; then
514
+ # 12:20 pm has to be caught and converted to 00:20 pm
515
+ if [ " $( echo ${build_time: 6} ) " = " PM " -o " $( echo ${build_time : 6} ) " = " pm" ] && [ " $( echo ${build_time: 0: 2} ) " = " 12" ]; then
514
516
build_time=" ${build_time/ 12/ 00} "
515
517
fi
516
518
517
- # 12:20 am hast to be caught and converted to 00:20 am
518
- if [ " $( echo ${build_time: 6} ) " = " am" ] && [ " $( echo ${build_time: 0: 2} ) " = " 12" ]; then
519
+ # 12:20 am has to be caught and converted to 00:20 am
520
+ if [ " $( echo ${build_time: 6} ) " = " AM " -o " $( echo ${build_time : 6} ) " = " am" ] && [ " $( echo ${build_time: 0: 2} ) " = " 12" ]; then
519
521
build_time=" ${build_time/ 12/ 00} "
520
522
fi
521
523
@@ -542,12 +544,15 @@ isDay() {
542
544
if [[ -z " $cur_time " ]]; then
543
545
cur_time=" $build_time "
544
546
fi
547
+ echo $cur_time
545
548
546
549
local sunrise=$( getSunrise " $api_output " )
547
550
local sunset=$( getSunset " $api_output " )
548
551
549
552
sunrise=$( makeComparable " $sunrise " )
553
+ echo $sunrise
550
554
sunset=$( makeComparable " $sunset " )
555
+ echo $sunset
551
556
552
557
# Sounds strange, but some cities don't build the rss-feed over
553
558
# night, the last time a few minutes before sunset. First Workaround:
@@ -581,27 +586,35 @@ isDay() {
581
586
# return: comparable time in minutes
582
587
makeComparable () {
583
588
local time=" $1 "
589
+ local ispm=1
584
590
585
- if [[ -n " $( echo $time | grep am ) " ]]; then
591
+ if [[ -n " $( echo $time | grep ' am\|AM ' ) " ]]; then
586
592
# it's am
587
593
# remove all non-digits:
588
- time=${time// [a-z: ]/ }
589
- else
590
- # it's pm, must add 1200
591
- time=${time// [a-z: ]/ }
592
- time=$(( 10 #$time + 1200 ))
594
+ ispm=0
593
595
fi
596
+ time=${time// [a-z:A-Z: ]/ }
597
+
594
598
local length=${# time}
595
599
if [[ " $length " -eq 3 ]]; then
596
600
# 1:30
597
601
local hours=${time: 0: 1}
598
602
local minutes=${time: 1: 2}
599
603
else
600
- # 11:30
601
- local hours=${time: 0: 2}
602
- local minutes=${time: 2: 2}
604
+ if [[ " $length " -eq 2 ]]; then
605
+ # 7:6 - yql irregularity
606
+ local hours=${time: 0: 1}
607
+ local minutes=${time: 1: 1}
608
+ else
609
+ # 11:30
610
+ local hours=${time: 0: 2}
611
+ local minutes=${time: 2: 2}
612
+ fi
603
613
fi
604
614
time=$(( 10 #$hours * 60 + 10 #$minutes ))
615
+ if [[ " $ispm " -eq 1 ]]; then
616
+ time=$(( 10 #$time + 1200 ))
617
+ fi
605
618
echo $time
606
619
}
607
620
@@ -820,7 +833,7 @@ while [[ $# -gt 0 ]] ; do
820
833
;;
821
834
822
835
--version)
823
- echo " izulu 0.6.1 "
836
+ echo " izulu 0.6.2 "
824
837
exit 0
825
838
;;
826
839
esac
0 commit comments