Initial commit - owm - Print 5 day / 3 hour forecast using api.openweathermap.org
(HTM) hg clone https://bitbucket.org/iamleot/owm
(DIR) Log
(DIR) Files
(DIR) Refs
(DIR) README
---
(DIR) changeset 46ce5e5ec9c10d511a6cbcf85e11fa707770509d
(HTM) Author: Leonardo Taccari <iamleot@gmail.com>
Date: Sat, 8 Jun 2019 21:14:49
Initial commit
Diffstat:
README | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
owm.sh | 47 +++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 107 insertions(+), 0 deletions(-)
---
diff -r 000000000000 -r 46ce5e5ec9c1 README
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/README Sat Jun 08 21:14:49 2019 +0200
@@ -0,0 +1,60 @@
+owm is a shell one-liner^W script that prints 5 day / 3 hour forecast
+using api.openweathermap.org.
+
+The output is a TSV (tab-separated values) with 3 fields, in the
+following order (to add an header to print them please pass the
+`-h` option to owm):
+
+ - date
+ - temperature in °C
+ - condition
+
+An API key and city are needed and are passed to `owm` respectively
+via OWM_APIKEY and OWM_CITYID environment variables, e.g.:
+
+ % date
+ Sat Jun 8 21:08:21 CEST 2019
+ % env OWM_APIKEY=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX OWM_CITYID=6539761 owm -h
+ Date °C Condition
+ 2019-06-08 21:00 Clear 21.69
+ 2019-06-09 00:00 Clouds 20.53
+ 2019-06-09 03:00 Clouds 20.12
+ 2019-06-09 06:00 Clouds 24.63
+ 2019-06-09 09:00 Clear 31.88
+ 2019-06-09 12:00 Clear 34.69
+ 2019-06-09 15:00 Clouds 34.13
+ 2019-06-09 18:00 Clouds 29.61
+ 2019-06-09 21:00 Clouds 25.42
+ 2019-06-10 00:00 Clouds 23.85
+ 2019-06-10 03:00 Clouds 22.25
+ 2019-06-10 06:00 Clouds 26.14
+ 2019-06-10 09:00 Clouds 32.99
+ 2019-06-10 12:00 Clouds 35.83
+ 2019-06-10 15:00 Clouds 33.56
+ 2019-06-10 18:00 Clouds 28.57
+ 2019-06-10 21:00 Clouds 24.84
+ 2019-06-11 00:00 Clouds 22.64
+ 2019-06-11 03:00 Clear 21.15
+ 2019-06-11 06:00 Rain 24.28
+ 2019-06-11 09:00 Rain 27.05
+ 2019-06-11 12:00 Clouds 30.6
+ 2019-06-11 15:00 Clouds 29.9
+ 2019-06-11 18:00 Clouds 26.15
+ 2019-06-11 21:00 Clear 22.85
+ 2019-06-12 00:00 Clouds 21.25
+ 2019-06-12 03:00 Clouds 20.55
+ 2019-06-12 06:00 Clouds 24.45
+ 2019-06-12 09:00 Rain 29.97
+ 2019-06-12 12:00 Clouds 32.43
+ 2019-06-12 15:00 Clear 31.85
+ 2019-06-12 18:00 Clear 28.27
+ 2019-06-12 21:00 Clear 23.87
+ 2019-06-13 00:00 Clear 22.33
+ 2019-06-13 03:00 Clouds 21.75
+ 2019-06-13 06:00 Clouds 26.1
+ 2019-06-13 09:00 Clear 32.44
+ 2019-06-13 12:00 Clouds 33.47
+ 2019-06-13 15:00 Clouds 32.39
+ 2019-06-13 18:00 Clouds 29.89
+
+To use `owm` `curl` and `jq` are needed.
diff -r 000000000000 -r 46ce5e5ec9c1 owm.sh
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/owm.sh Sat Jun 08 21:14:49 2019 +0200
@@ -0,0 +1,47 @@
+#!/bin/sh
+
+#
+# Copyright (c) 2019 Leonardo Taccari
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+#
+# 1. Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in the
+# documentation and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS
+# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+# POSSIBILITY OF SUCH DAMAGE.
+#
+
+
+apikey=${OWM_APIKEY}
+cityid=${OWM_CITYID}
+units=metric
+
+req="https://api.openweathermap.org/data/2.5/forecast?id=${cityid}&units=${units}&appid=${apikey}"
+
+if [ $# -eq 1 ] && [ "$1" = "-h" ]; then
+ printf "Date\t°C\tCondition\n"
+fi
+
+curl -s "$req" | \
+ jq -r \
+ '.list[] |
+ ( (.dt | strftime("%Y-%m-%d %H:%M")) + "\t" +
+ .weather[0].main + "\t" +
+ (.main.temp | tostring)
+ )'