Skip to content

Commit 1c95483

Browse files
committed
Workaround Yahoo oauth api restriction
1 parent 8571cdf commit 1c95483

File tree

1 file changed

+36
-23
lines changed

1 file changed

+36
-23
lines changed

izulu

+36-23
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ getWeather() {
2424
local woeid="$1"
2525

2626
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'
2828
}
2929

3030
# get WOEID uesed for as location by Yahoo
@@ -44,8 +44,7 @@ getYahooWOEID() {
4444
# return: full xml-response
4545
getYahooXML() {
4646
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")
4948
echo "$yahooWeather"
5049
}
5150

@@ -55,7 +54,7 @@ getYahooXML() {
5554
getSunrise() {
5655
local api_output="$1"
5756

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'
5958
}
6059

6160
# get date of sunset from yahoo
@@ -64,7 +63,7 @@ getSunrise() {
6463
getSunset() {
6564
local api_output="$1"
6665

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'
6867
}
6968

7069
# map forecast-code to one of the icons
@@ -264,11 +263,11 @@ setImage() {
264263
if [ "$PREVIEW" == "TRUE" ];then
265264
for i in {1..5};do
266265
# 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')
268267
local icon=$(chooseForecastIcon "$forecast")
269268
local tmpicon=$(mktemp)
270269
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')
272271
convert "$tmpicon" -gravity South -fill '#c0bfbd' -font Helvetica -background '#0000' -pointsize 16 -splice 0x24 -annotate +0+2 "$day" "$tmpicon"
273272

274273
# at least +20 y height to be above typical taskbar
@@ -277,7 +276,10 @@ setImage() {
277276
fi
278277

279278
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/.*/}
281283
convert -gravity "$TEMPERATURE_GRAVITY" "$tmpimage" -font Helvetica -pointsize 36 -fill '#c0bfbd' -background '#0000' -annotate "$TEMPERATURE_MARGIN" "$temperature°C" "$tmpimage"
282284
fi
283285

@@ -506,16 +508,16 @@ getFlickrImage() {
506508
getCurrentTime() {
507509
local api_output="$1"
508510

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 '.')
510512
local build_time=$(echo $build_date | sed 's/.*\(..:.....\).*/\1/')
511513

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
514516
build_time="${build_time/12/00}"
515517
fi
516518

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
519521
build_time="${build_time/12/00}"
520522
fi
521523

@@ -542,12 +544,15 @@ isDay() {
542544
if [[ -z "$cur_time" ]];then
543545
cur_time="$build_time"
544546
fi
547+
echo $cur_time
545548

546549
local sunrise=$(getSunrise "$api_output")
547550
local sunset=$(getSunset "$api_output")
548551

549552
sunrise=$(makeComparable "$sunrise")
553+
echo $sunrise
550554
sunset=$(makeComparable "$sunset")
555+
echo $sunset
551556

552557
#Sounds strange, but some cities don't build the rss-feed over
553558
#night, the last time a few minutes before sunset. First Workaround:
@@ -581,27 +586,35 @@ isDay() {
581586
#return: comparable time in minutes
582587
makeComparable() {
583588
local time="$1"
589+
local ispm=1
584590

585-
if [[ -n "$(echo $time | grep am)" ]];then
591+
if [[ -n "$(echo $time | grep 'am\|AM')" ]];then
586592
#it's am
587593
#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
593595
fi
596+
time=${time//[a-z:A-Z: ]/}
597+
594598
local length=${#time}
595599
if [[ "$length" -eq 3 ]];then
596600
#1:30
597601
local hours=${time:0:1}
598602
local minutes=${time:1:2}
599603
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
603613
fi
604614
time=$((10#$hours * 60 + 10#$minutes))
615+
if [[ "$ispm" -eq 1 ]];then
616+
time=$((10#$time + 1200))
617+
fi
605618
echo $time
606619
}
607620

@@ -820,7 +833,7 @@ while [[ $# -gt 0 ]] ; do
820833
;;
821834

822835
--version)
823-
echo "izulu 0.6.1"
836+
echo "izulu 0.6.2"
824837
exit 0
825838
;;
826839
esac

0 commit comments

Comments
 (0)