Updated forecast.sh with colors, wrote forecast.sh into readme

pull/2/head
Steven Saus 5 years ago
parent 59cdb17a91
commit 34e896b096
  1. 28
      README.md
  2. 2
      bashcolors
  3. 72
      forecast.sh
  4. 1
      weather.sh
  5. 1
      weather_sh.rc

@ -1,5 +1,6 @@
# weather.sh
A bash script to get the weather from OpenWeatherMap and output to the terminal, Openbox, or HTML
# weather.sh and forecast.sh
A bash script to get the weather and forecast from OpenWeatherMap and output
to the terminal, Openbox, or HTML
## Contents
@ -24,6 +25,18 @@ from [BashWeather](https://github.com/jdotjdot/BashWeather),
[bash-weather](https://github.com/szantaii/bash-weather),
and many more that I forgot to save the URLs of.
`forecast.sh` gets the forecast from [OpenWeatherMap](http://openweathermap.org/)
and likewise displays the results. OpenWeatherMap forecasts are at three hour
intervals (0800, 1100, 1400, etc). It displays all forecasts for the next
twenty four hours, then displays the closest time forecast for the day after
that. For example, if it's 1136 (as I'm writing this) it shows all forecasts
through the 1100 forecast the next day, then the 1100 forecast for each
subsequent day. Options and `.rc` file are *the same* as for `weather.sh`.
If you wish to show both together, simply execute:
`weather.sh && forecast.sh`
## 2. License
This project is licensed under the MIT license. For the full license, see `LICENSE`.
@ -50,9 +63,9 @@ Optional: For colors in terminal, save `bashcolors` in this repository to
## 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.
Run `weather.sh` or `forecast.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
@ -65,7 +78,8 @@ icons displayed for the weather.
### Command-line options
`weather.sh` can be started with the following command line options:
`weather.sh` and `forecast.sh` can be started with the following command line
options:
* `-k` Specifies OpenWeatherMap API key from the command-line.
* `-l city_name` Sets the city for manual weather lookup.
@ -84,4 +98,4 @@ will override the API key set in the file._
* Add in sunrise/sunset
* HTML colored output
* Current location instead of hardcoded

@ -8,7 +8,7 @@ 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')
LGRAY=$(echo -en '\033[00;37m')
LRED=$(echo -en '\033[01;31m')
LGREEN=$(echo -en '\033[01;32m')
LYELLOW=$(echo -en '\033[01;33m')

@ -17,6 +17,7 @@ lastUpdateTime=0
FeelsLike=0
dynamicUpdates=0
UseIcons="True"
colors="False"
########################################################################
# Reading in rc
@ -28,6 +29,7 @@ if [ -f "$HOME/.config/weather_sh.rc" ];then
defaultLocation=${line[1]}
degreeCharacter=${line[2]}
UseIcons=${line[3]}
colors=${line[4]}
fi
########################################################################
@ -54,6 +56,12 @@ option="$1"
shift ;;
-f) degreeCharacter="f"
shift ;;
-c)
if [ -f "$HOME/.bashcolors" ];then
source "$HOME/.bashcolors"
colors="True"
fi
shift ;;
esac
done
@ -152,8 +160,10 @@ while true; do
AsOf=$(date +"%Y-%m-%d %R" -d @$lastfileupdate)
TomorrowDate=$(date -d '+1 day' +"%s")
NowHour=$(date +"%-H")
NowLow=$((NowHour + 1))
NowHigh=$((NowHour - 1))
if [ "$OpenBox" = "False" ];then
if [ "$HTML" = "False" ];then
@ -161,13 +171,33 @@ while true; do
fi
fi
if [ "$Terminal" = "True" ];then
echo "Forecast for $Station as of: $AsOf "
if [ "$colors" = "True" ]; then
echo "Forecast for $Station as of: ${YELLOW}$AsOf${RESTORE} "
else
echo "Forecast for $Station as of: $AsOf "
fi
let i=0
while [ $i -lt 40 ]; do
ShortDate=$(date +"%m/%d@%R" -d @${NixDate[$i]})
printf "%-12s %-2s%-20s %-15s %-14s %-14s %-14s\n" "$ShortDate:" "${icon[$i]} " "${LongWeather[$i]}" "Temp:${temperature[$i]}°${degreeCharacter^^}" "Wind:${WindSpeed[$i]}$windunit" "Humidity:${Humidity[$i]}%" "Cloud Cover:${CloudCover[$i]}%"
while [ $i -lt 40 ]; do
CastDate=$(date +"%s" -d @${NixDate[$i]})
#CastDate=$(date +"%m%d" -d @${NixDate[$i]})
if [ $CastDate -le $TomorrowDate ]; then
ShortDate=$(date +"%m/%d@%R" -d @${NixDate[$i]})
if [ "$colors" = "True" ]; then
printf "${YELLOW}%-11s${RESTORE}: ${CYAN}%-2s%-16s${RESTORE} Temp:${CYAN}%-6s${RESTORE} Wind:${MAGENTA}%-6s${RESTORE} Humidity:${GREEN}%-4s${RESTORE} Clouds:${GREEN}%-4s${RESTORE}\n" "$ShortDate" "${icon[$i]} " "${LongWeather[$i]}" "${temperature[$i]}°${degreeCharacter^^}" "${WindSpeed[$i]}$windunit" "${Humidity[$i]}%" "${CloudCover[$i]}%"
else
printf "%-12s %-2s%-20s %-15s %-14s %-14s %-14s\n" "$ShortDate:" "${icon[$i]} " "${LongWeather[$i]}" "Temp:${temperature[$i]}°${degreeCharacter^^}" "Wind:${WindSpeed[$i]}$windunit" "Humidity:${Humidity[$i]}%" "Cloud Cover:${CloudCover[$i]}%"
fi
else
CastHour=$(date +"%-H" -d @${NixDate[$i]})
if [ "$CastHour" -ge "$NowHigh" ] && [ "$CastHour" -le "$NowLow" ]; then
ShortDate=$(date +"%m/%d@%R" -d @${NixDate[$i]})
if [ "$colors" = "True" ]; then
printf "${RED}%-11s${RESTORE}: ${CYAN}%-2s%-16s${RESTORE} Temp:${CYAN}%-6s${RESTORE} Wind:${MAGENTA}%-6s${RESTORE} Humidity:${GREEN}%-4s${RESTORE} Clouds:${GREEN}%-4s${RESTORE}\n" "$ShortDate" "${icon[$i]} " "${LongWeather[$i]}" "${temperature[$i]}°${degreeCharacter^^}" "${WindSpeed[$i]}$windunit" "${Humidity[$i]}%" "${CloudCover[$i]}%"
else
printf "%-12s %-2s%-20s %-15s %-14s %-14s %-14s\n" "$ShortDate:" "${icon[$i]} " "${LongWeather[$i]}" "Temp:${temperature[$i]}°${degreeCharacter^^}" "Wind:${WindSpeed[$i]}$windunit" "Humidity:${Humidity[$i]}%" "Cloud Cover:${CloudCover[$i]}%"
fi
fi
fi
i=$((i + 1))
done
fi
@ -177,8 +207,17 @@ while true; do
printf '<item label="Forecast for %s as of %s" />\n' "$Station" "$AsOf"
let i=0
while [ $i -lt 40 ]; do
ShortDate=$(date +"%m/%d@%R" -d @${NixDate[$i]})
printf '<item label="%-12s %-2s%-20s %-15s %-14s %-14s %-14s/>\n' "$ShortDate:" "${icon[$i]} " "${LongWeather[$i]}" "Temp:${temperature[$i]}°${degreeCharacter^^}" "Wind:${WindSpeed[$i]}$windunit" "Humidity:${Humidity[$i]}%" "Cloud Cover:${CloudCover[$i]}%"
CastDate=$(date +"%m%d" -d @${NixDate[$i]})
if [ $CastDate = $NowDate ]; then
ShortDate=$(date +"%m/%d@%R" -d @${NixDate[$i]})
printf '<item label="%-12s %-2s%-20s %-15s %-14s %-14s %-14s/>\n' "$ShortDate:" "${icon[$i]} " "${LongWeather[$i]}" "Temp:${temperature[$i]}°${degreeCharacter^^}" "Wind:${WindSpeed[$i]}$windunit" "Humidity:${Humidity[$i]}%" "Cloud Cover:${CloudCover[$i]}%"
else
CastHour=$(date +"%-H" -d @${NixDate[$i]})
if [ "$CastHour" -ge "$NowHigh" ] && [ "$CastHour" -le "$NowLow" ]; then
ShortDate=$(date +"%m/%d@%R" -d @${NixDate[$i]})
printf '<item label="%-12s %-2s%-20s %-15s %-14s %-14s %-14s/>\n' "$ShortDate:" "${icon[$i]} " "${LongWeather[$i]}" "Temp:${temperature[$i]}°${degreeCharacter^^}" "Wind:${WindSpeed[$i]}$windunit" "Humidity:${Humidity[$i]}%" "Cloud Cover:${CloudCover[$i]}%"
fi
fi
i=$((i + 1))
done
echo '</openbox_pipe_menu>'
@ -187,8 +226,17 @@ while true; do
echo "Forecast for $Station as of: $AsOf <br />"
let i=0
while [ $i -lt 40 ]; do
ShortDate=$(date +"%m/%d@%R" -d @${NixDate[$i]})
printf "%-12s %-2s%-20s %-15s %-14s %-14s %-14s<br />\n" "$ShortDate:" "${icon[$i]} " "${LongWeather[$i]}" "Temp:${temperature[$i]}°${degreeCharacter^^}" "Wind:${WindSpeed[$i]}$windunit" "Humidity:${Humidity[$i]}%" "Cloud Cover:${CloudCover[$i]}%"
CastDate=$(date +"%m%d" -d @${NixDate[$i]})
if [ $CastDate = $NowDate ]; then
ShortDate=$(date +"%m/%d@%R" -d @${NixDate[$i]})
printf "%-12s %-2s%-20s %-15s %-14s %-14s %-14s<br />\n" "$ShortDate:" "${icon[$i]} " "${LongWeather[$i]}" "Temp:${temperature[$i]}°${degreeCharacter^^}" "Wind:${WindSpeed[$i]}$windunit" "Humidity:${Humidity[$i]}%" "Cloud Cover:${CloudCover[$i]}%"
else
CastHour=$(date +"%-H" -d @${NixDate[$i]})
if [ "$CastHour" -ge "$NowHigh" ] && [ "$CastHour" -le "$NowLow" ]; then
ShortDate=$(date +"%m/%d@%R" -d @${NixDate[$i]})
printf "%-12s %-2s%-20s %-15s %-14s %-14s %-14s<br />\n" "$ShortDate:" "${icon[$i]} " "${LongWeather[$i]}" "Temp:${temperature[$i]}°${degreeCharacter^^}" "Wind:${WindSpeed[$i]}$windunit" "Humidity:${Humidity[$i]}%" "Cloud Cover:${CloudCover[$i]}%"
fi
fi
i=$((i + 1))
done
fi

@ -22,6 +22,7 @@ if [ -f "$HOME/.config/weather_sh.rc" ];then
defaultLocation=${line[1]}
degreeCharacter=${line[2]}
UseIcons=${line[3]}
colors=${line[4]}
fi
while [ $# -gt 0 ]; do

@ -2,3 +2,4 @@ NotARealAPIKey
Dayton
f
False
True

Loading…
Cancel
Save