Added switch and rc for icon display

pull/2/head
Steven Saus 5 years ago
parent f2196f264b
commit be8bfa9009
  1. 9
      README.md
  2. 33
      weather.sh
  3. 1
      weather_sh.rc

@ -35,15 +35,22 @@ This project is licensed under the MIT license. For the full license, see `LICEN
* `curl` command-line tool for getting data using HTTP protocol. cURL can be found in the `curl` package on major Linux distributions.
* `grep` command-line tool used for parsing downloaded XML data. `grep` can be found in the `grep` package on major Linux distributions.
* `jq` command-line tool for parsing JSON data. `jq` can be found in the `jq` package on major Linux distributions.
* `tr` command-line tool for parsing JSON data. `tr` can be found in the `tr` package on major Linux distributions.
## 4. How to use
Run `weather.sh` with the appropriate commandline switches (below). If
the current conditions do not qualify for the heat index or wind chill,
it is not displayed.
### `weather_sh.rc`
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 third line is your default degree character (either `c` or `f`).
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.
### Command-line options

@ -12,12 +12,14 @@ data=0
lastUpdateTime=0
FeelsLike=0
dynamicUpdates=0
UseIcons="True"
if [ -f "$HOME/.config/weather_sh.rc" ];then
readarray -t line < "$HOME/.config/weather_sh.rc"
apiKey=${line[0]}
defaultLocation=${line[1]}
degreeCharacter=${line[2]}
UseIcons=${line[3]}
fi
while [ $# -gt 0 ]; do
@ -77,20 +79,23 @@ while true; do
####################################################################
# Current conditions (and icon)
####################################################################
icons=$(echo $data | jq -r .weather[].icon | tr '\n' ' ')
iconval=${icons%?}
case $iconval in
01*) icon="☀";;
02*) icon="🌤";;
03*) icon="🌥";;
04*) icon="☁";;
09*) icon="🌧";;
10*) icon="🌦";;
11*) icon="🌩";;
13*) icon="🌨";;
50*) icon="🌫";;
esac
if [ "$UseIcons" = "True" ];then
icons=$(echo $data | jq -r .weather[].icon | tr '\n' ' ')
iconval=${icons%?}
case $iconval in
01*) icon="☀";;
02*) icon="🌤";;
03*) icon="🌥";;
04*) icon="☁";;
09*) icon="🌧";;
10*) icon="🌦";;
11*) icon="🌩";;
13*) icon="🌨";;
50*) icon="🌫";;
esac
else
icon=""
fi
ShortWeather=$(echo $data | jq -r .weather[].main | tr '\n' ' ')
LongWeather=$(echo $data | jq -r .weather[].description | sed -E 's/\S+/\u&/g' | tr '\n' ' ')

@ -1,3 +1,4 @@
NotARealAPIKey
Dayton
f
False

Loading…
Cancel
Save