Added colors to forecast terminal output

pull/2/head
Steven Saus 5 years ago
parent c3c40a7635
commit 59cdb17a91
  1. 36
      README.md
  2. 20
      bashcolors
  3. 2
      forecast.sh
  4. 45
      weather.sh

@ -7,6 +7,7 @@ A bash script to get the weather from OpenWeatherMap and output to the terminal,
2. [License](#2-license)
3. [Prerequisites](#3-prerequisites)
4. [How to use](#4-how-to-use)
5. [TODO](#5-todo)
***
@ -31,12 +32,21 @@ This project is licensed under the MIT license. For the full license, see `LICEN
* OpenWeatherMap API key ([http://openweathermap.org/appid](http://openweathermap.org/appid)).
* Bash shell ≥ 4.2.
* `bc` basic calculator for floating point arithmetic. Can be found in the `bc` package on major Linux distributions.
* `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.
* `awk` command-line tool for parsing JSON data. `awk` can be found in the `awk` package on major Linux distributions.
* `bc` basic calculator for floating point arithmetic. Can be found in the
`bc` package on major Linux distributions.
* `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.
* `awk` command-line tool for parsing JSON data. `awk` can be found in the
`awk` package on major Linux distributions.
Optional: For colors in terminal, save `bashcolors` in this repository to
`.bashcolors` in your `$HOME` directory.
## 4. How to use
@ -63,5 +73,15 @@ icons displayed for the weather.
* `-h` Output HTML formatted text
* `-o` Output OpenBox output
* `-f` Use imperial (farenheit, inches Hg, mph) units; default is metric
_Note: If the OpenWeatherMap API key is specified from the command-line, it will override the API key set in the file._
* `-c` Use colored output in the terminal if `.bashcolors` is in the home
dir. Note that if you want to alter the colors, you will have to manually
alter the script.
_Note: If the OpenWeatherMap API key is specified from the command-line, it
will override the API key set in the file._
## 5. Todo
* Add in sunrise/sunset
* HTML colored output

@ -0,0 +1,20 @@
#Derived from https://gist.githubusercontent.com/elucify/c7ccfee9f13b42f11f81/raw/9f27e072aadc4df6f84d515309c82585a8a13d8e/gistfile1.txt
RESTORE=$(echo -en '\033[0m')
RED=$(echo -en '\033[00;31m')
GREEN=$(echo -en '\033[00;32m')
YELLOW=$(echo -en '\033[00;33m')
BLUE=$(echo -en '\033[00;34m')
MAGENTA=$(echo -en '\033[00;35m')
PURPLE=$(echo -en '\033[00;35m')
CYAN=$(echo -en '\033[00;36m')
LIGHTGRAY=$(echo -en '\033[00;37m')
LRED=$(echo -en '\033[01;31m')
LGREEN=$(echo -en '\033[01;32m')
LYELLOW=$(echo -en '\033[01;33m')
LBLUE=$(echo -en '\033[01;34m')
LMAGENTA=$(echo -en '\033[01;35m')
LPURPLE=$(echo -en '\033[01;35m')
LCYAN=$(echo -en '\033[01;36m')
WHITE=$(echo -en '\033[01;37m')

@ -69,7 +69,7 @@ fi
dataPath="/tmp/fore-$defaultLocation.json"
if [ ! -e $dataPath ];then
touch $dataPath
data=$(curl "http://api.openweathermap.org/data/2.5/forecast?q=$defaultLocation&units=metric&appid=$apiKey")
data=$(curl -s "http://api.openweathermap.org/data/2.5/forecast?q=$defaultLocation&units=metric&appid=$apiKey")
echo $data > $dataPath
else
data=$(cat $dataPath)

@ -13,6 +13,8 @@ lastUpdateTime=0
FeelsLike=0
dynamicUpdates=0
UseIcons="True"
colors=0
if [ -f "$HOME/.config/weather_sh.rc" ];then
readarray -t line < "$HOME/.config/weather_sh.rc"
@ -42,6 +44,12 @@ option="$1"
shift ;;
-f) degreeCharacter="f"
shift ;;
-c)
if [ -f "$HOME/.bashcolors" ];then
source "$HOME/.bashcolors"
colors="True"
fi
shift ;;
esac
done
@ -193,18 +201,33 @@ while true; do
fi
fi
if [ "$Terminal" = "True" ];then
echo "Station: $Station, $Country $Lat / $Long"
echo "As Of: $AsOf "
echo "Current Conditions: $icon $LongWeather"
#echo "$icon $ShortWeather"
echo "Temp: $temperature°${degreeCharacter^^}"
if [ "$FeelsLike" = "1" ];then
echo "Feels Like: $FeelsLikeTemp°${degreeCharacter^^}"
if [ "$colors" = "True" ]; then
echo "Station: $Station, $Country $Lat / $Long"
echo "As Of: ${YELLOW}$AsOf ${RESTORE}"
echo "Right Now: ${CYAN}$icon $LongWeather${RESTORE}"
#echo "$icon $ShortWeather"
echo "Temp: ${CYAN}$temperature°${degreeCharacter^^}${RESTORE}"
if [ "$FeelsLike" = "1" ];then
echo "Feels Like: ${RED}$FeelsLikeTemp°${degreeCharacter^^}${RESTORE}"
fi
echo "Pressure: ${GREEN}$pressure$pressureunit${MAGENTA}"
echo -e \\u$winddir "$WindSpeed$windunit${RESTORE} Gusts: ${MAGENTA}$WindGusts$windunit${RESTORE}"
echo "Humidity: ${GREEN}$Humidity%${RESTORE}"
echo "Cloud Cover: ${GREEN}$CloudCover%${RESTORE}"
else
echo "Station: $Station, $Country $Lat / $Long"
echo "As Of: $AsOf "
echo "Right Now: $icon $LongWeather"
#echo "$icon $ShortWeather"
echo "Temp: $temperature°${degreeCharacter^^}"
if [ "$FeelsLike" = "1" ];then
echo "Feels Like: $FeelsLikeTemp°${degreeCharacter^^}"
fi
echo "Pressure: $pressure$pressureunit"
echo -e \\u$winddir "$WindSpeed$windunit Gusts: $WindGusts$windunit"
echo "Humidity: $Humidity%"
echo "Cloud Cover: $CloudCover%"
fi
echo "Pressure: $pressure$pressureunit"
echo -e \\u$winddir "$WindSpeed$windunit Gusts: $WindGusts$windunit"
echo "Humidity: $Humidity%"
echo "Cloud Cover: $CloudCover%"
fi
if [ "$OpenBox" = "True" ]; then
echo '<openbox_pipe_menu>'

Loading…
Cancel
Save