Lookup by city ID OR name, example output as part of README

pull/2/head
Steven Saus 5 years ago
parent 34e896b096
commit 6dba071a2d
  1. 14
      README.md
  2. BIN
      example_output.png
  3. 32
      forecast.sh
  4. 1
      getlocation.sh
  5. 36
      weather.sh
  6. 2
      weather_sh.rc

@ -2,6 +2,9 @@
A bash script to get the weather and forecast from OpenWeatherMap and output
to the terminal, Openbox, or HTML
![Output example][output]
[output]: https://i.postimg.cc/T1WsDkJs/2019-05-26-1558885180-667x428-scrot.png "Example output"
## Contents
1. [About](#1-about)
@ -71,7 +74,7 @@ chill, it is not displayed.
Copy (and edit, as appropriate) the `weather_sh.rc` file to `$HOME\.config`.
The first line is the OpenWeatherMap API key
The second line is your default location
The second line is your default location. (See note below)
The third line is your default degree character (either `c` or `f`)
The fourth line is True or False depending on whether or not you want
icons displayed for the weather.
@ -82,7 +85,7 @@ icons displayed for the weather.
options:
* `-k` Specifies OpenWeatherMap API key from the command-line.
* `-l city_name` Sets the city for manual weather lookup.
* `-l city_name` Sets the city for manual weather lookup. (see note below)
* `-t` Output to the terminal/stdout (default if no output is specified)
* `-h` Output HTML formatted text
* `-o` Output OpenBox output
@ -94,8 +97,13 @@ options:
_Note: If the OpenWeatherMap API key is specified from the command-line, it
will override the API key set in the file._
_Note: It is **STRONGLY** recommended to use the City ID from OpenWeatherMap
instead of a city name. Instructions on finding your city's City ID
[here](https://www.dmopress.com/openweathermap-howto/) ._
## 5. Todo
* Add in sunrise/sunset
* HTML colored output
* Current location instead of hardcoded
* Current location instead of hardcoded
- this is problematic due to the way the API looks up city names.

Binary file not shown.

After

Width:  |  Height:  |  Size: 93 KiB

@ -29,7 +29,17 @@ if [ -f "$HOME/.config/weather_sh.rc" ];then
defaultLocation=${line[1]}
degreeCharacter=${line[2]}
UseIcons=${line[3]}
colors=${line[4]}
temp=${line[4]}
if [ "$temp" = "True" ];then
if [ -f "$HOME/.bashcolors" ];then
source "$HOME/.bashcolors"
colors="True"
else
colors=""
fi
else
colors=""
fi
fi
########################################################################
@ -70,6 +80,13 @@ if [ -z $apiKey ];then
exit
fi
#Is it City ID or a string?
case $defaultLocation in
''|*[!0-9]*) CityID="False" ;;
*) CityID="True" ;;
esac
########################################################################
# Do we need a new datafile? If so, get it.
########################################################################
@ -77,7 +94,12 @@ fi
dataPath="/tmp/fore-$defaultLocation.json"
if [ ! -e $dataPath ];then
touch $dataPath
data=$(curl -s "http://api.openweathermap.org/data/2.5/forecast?q=$defaultLocation&units=metric&appid=$apiKey")
if [ "$CityID" = "True" ];then
data=$(curl -s "http://api.openweathermap.org/data/2.5/forecast?id=$defaultLocation&units=metric&appid=$apiKey")
else
data=$(curl -s "http://api.openweathermap.org/data/2.5/forecast?q=$defaultLocation&units=metric&appid=$apiKey")
fi
echo $data > $dataPath
else
data=$(cat $dataPath)
@ -88,7 +110,11 @@ lastUpdateTime=$(($(date +%s) -600))
while true; do
lastfileupdate=$(date -r $dataPath +%s)
if [ $(($(date +%s)-$lastfileupdate)) -ge 600 ];then
data=$(curl -s "http://api.openweathermap.org/data/2.5/forecast?q=$defaultLocation&units=metric&appid=$apiKey")
if [ "$CityID" = "True" ];then
data=$(curl -s "http://api.openweathermap.org/data/2.5/forecast?id=$defaultLocation&units=metric&appid=$apiKey")
else
data=$(curl -s "http://api.openweathermap.org/data/2.5/forecast?q=$defaultLocation&units=metric&appid=$apiKey")
fi
echo $data > $dataPath
fi
if [ $(($(date +%s)-$lastUpdateTime)) -ge 600 ]; then

@ -0,0 +1 @@
curl http://api.db-ip.com/v2/free/184.59.91.149/city

@ -13,8 +13,8 @@ lastUpdateTime=0
FeelsLike=0
dynamicUpdates=0
UseIcons="True"
colors=0
colors="False"
CityID="True"
if [ -f "$HOME/.config/weather_sh.rc" ];then
readarray -t line < "$HOME/.config/weather_sh.rc"
@ -22,7 +22,17 @@ if [ -f "$HOME/.config/weather_sh.rc" ];then
defaultLocation=${line[1]}
degreeCharacter=${line[2]}
UseIcons=${line[3]}
colors=${line[4]}
temp=${line[4]}
if [ "$temp" = "True" ];then
if [ -f "$HOME/.bashcolors" ];then
source "$HOME/.bashcolors"
colors="True"
else
colors=""
fi
else
colors=""
fi
fi
while [ $# -gt 0 ]; do
@ -59,11 +69,23 @@ if [ -z $apiKey ];then
exit
fi
#Is it City ID or a string?
case $defaultLocation in
''|*[!0-9]*) CityID="False" ;;
*) CityID="True" ;;
esac
dataPath="/tmp/wth-$defaultLocation.json"
if [ ! -e $dataPath ];
then
touch $dataPath
data=$(curl "http://api.openweathermap.org/data/2.5/weather?q=$defaultLocation&units=metric&appid=$apiKey")
#The API call is different if city ID is used instead of string lookup
if [ "$CityID" = "True" ];then
data=$(curl "http://api.openweathermap.org/data/2.5/weather?id=$defaultLocation&units=metric&appid=$apiKey")
else
data=$(curl "http://api.openweathermap.org/data/2.5/weather?q=$defaultLocation&units=metric&appid=$apiKey")
fi
echo $data > $dataPath
else
data=$(cat $dataPath)
@ -73,7 +95,11 @@ lastUpdateTime=$(($(date +%s) -600))
while true; do
lastfileupdate=$(date -r $dataPath +%s)
if [ $(($(date +%s)-$lastfileupdate)) -ge 600 ];then
data=$(curl -s "http://api.openweathermap.org/data/2.5/weather?q=$defaultLocation&units=metric&appid=$apiKey")
if [ "$CityID" = "True" ];then
data=$(curl "http://api.openweathermap.org/data/2.5/weather?id=$defaultLocation&units=metric&appid=$apiKey")
else
data=$(curl "http://api.openweathermap.org/data/2.5/weather?q=$defaultLocation&units=metric&appid=$apiKey")
fi
echo $data > $dataPath
fi
if [ $(($(date +%s)-$lastUpdateTime)) -ge 600 ]; then

@ -1,5 +1,5 @@
NotARealAPIKey
Dayton
4509884
f
False
True

Loading…
Cancel
Save