diff options
Diffstat (limited to 'microposts/get-australia-weather.org')
-rw-r--r-- | microposts/get-australia-weather.org | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/microposts/get-australia-weather.org b/microposts/get-australia-weather.org new file mode 100644 index 0000000..246a6c4 --- /dev/null +++ b/microposts/get-australia-weather.org @@ -0,0 +1,56 @@ +#+title: A simple shell script to get Australian weather forecast from BoM + +#+date: <2022-01-13> + +In this micropost I'll show how to write your own android weather app +("app" in a liberal sense) to retrieve weather for an Australian town, +using Melbourne as an example. + +The short form (précis) 7-day forecasts, containing min / max +temperature, humidity level and chances of precipitation are available +as xml files [[http://www.bom.gov.au/catalogue/data-feeds.shtml][provided by the BoM]] - simply go there and get the link +for the state you are interested in. For Victoria it is +<ftp://ftp.bom.gov.au/anon/gen/fwo/IDV10753.xml>. + +So the first step is to download the xml to a temp directory, which +can be done with wget: + +#+begin_src sh +cd $PREFIX/tmp +rm IDV10753.xml || true +wget ftp://ftp.bom.gov.au/anon/gen/fwo/IDV10753.xml +#+end_src + +Next one needs to query the xml file for the relevant data. Locate +the city name, date, temperatures and chance of pricipitation using +the nice [[https://en.wikipedia.org/wiki/XMLStarlet][xmlstarlet]] tool and format them nicely. + +#+begin_src sh +result=`xml sel -t -m '//area[@description="Melbourne"]/forecast-period'\ + -v "substring-before(@start-time-local, 'T')" \ + -o " - min: " -v "element[@type='air_temperature_minimum']" \ + -o " - max: " -v "element[@type='air_temperature_maximum']" \ + -o " - " -v "text[@type='precis']" \ + -o " - chance of precipitation: " -v "text[@type='probability_of_precipitation']" \ + -n IDV10753.xml` +#+end_src + +And finally, send the forecast to yourself using [[https://f-droid.org/en/packages/com.termux.api][Termux:API]]. + +#+begin_src sh +echo -e "7-day weather forecast in Melbourne:\n${result}" | \ + termux-sms-send -n 044444444 # replace 044444444 with your phone number +#+end_src + +To use it in termux, it doesn't hurt to specify the location of the +shell in a shebang: + +#+begin_src sh +#!/data/data/com.termux/files/usr/bin/bash +#+end_src + +Finally, to make the script a bit more convenient to invoke, use +[[https://f-droid.org/en/packages/com.termux.widget/][Termux:Widget]], and copy the script to =~/.shortcut=, and you can make +it appear as a button in a desktop widget. + +Enjoy the Melbourne weather! |