blob: 246a6c4cdd1be86dd842f4b27f982b472dafb890 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
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!
|