commit 2402d42c77248597a53bbf760a95afab991c9538
parent aa55611c64969591f4356fe49364789cc8b3c1bb
Author: Frederic Cambus <fcambus@users.sourceforge.net>
Date: Thu, 16 Jan 2014 14:29:03 -0800
Merge pull request #41 from royhodgman/sun
added sunrise and sunset data to the display
Diffstat:
3 files changed, 56 insertions(+), 4 deletions(-)
diff --git a/README.md b/README.md
@@ -31,7 +31,7 @@ After cloning the repository, simply invoke the script by typing :
Any configuration options may also be passed in as command line options.
- ./ansiweather -l Moscow,RU -u metric -s true -f 5
+ ./ansiweather -l Moscow,RU -u metric -s true -f 5 -d true
@@ -47,6 +47,7 @@ Example : `~/.ansiweatherrc`
location:Moscow,RU
fetch_cmd:ftp -V -o -
units:metric
+ daylight:true
### Location
@@ -100,6 +101,11 @@ Show upcoming forecast for the next `N` days (for 0 <= N <= 7). `0` will show st
forecast:5
+### Display sunrise / sunset
+
+Toggle daylight display. Value can be either `true` or `false`.
+
+ daylight:false
## License
diff --git a/ansiweather b/ansiweather
@@ -89,8 +89,11 @@ symbols=$(get_config "symbols" || echo true)
# Show forecast : How many days, example "5". "0" is standard output
forecast=$(get_config "forecast" || echo 0)
+# Show daylight : "true" or "false"
+daylight=$(get_config "daylight" || echo false)
+
# Or get config options from command line flags
-while getopts l:u:s:f: option
+while getopts l:u:s:f:d: option
do
case "${option}"
in
@@ -98,6 +101,7 @@ do
u) units=${OPTARG};;
s) symbols=${OPTARG};;
f) forecast=${OPTARG};;
+ d) daylight=${OPTARG};;
esac
done
@@ -119,7 +123,8 @@ greeting_text=$(get_config "greeting" || echo "Current weather in")
wind_text=$(get_config "wind" || echo "Wind")
humidity_text=$(get_config "humidity" || echo "Humidity")
pressure_text=$(get_config "pressure" || echo "Pressure")
-
+sunrise_text=$(get_config "sunrise" || echo "Sunrise")
+sunset_text=$(get_config "sunset" || echo "Sunset")
###[ Unicode Symbols for icons ]###############################################
@@ -218,6 +223,35 @@ fi
+###[ Process Sunrise and Sunset data ]#########################################
+
+function epoch_to_time {
+ unamestr=$(uname)
+ if date -j -r $1 +"%r" > /dev/null 2>&1; then
+ # BSD
+ ret=$(date -j -r $1 +"%b %d %r")
+ else
+ # GNU
+ ret=$(date -d @$1 +"%b %d %r")
+ fi
+ echo $ret
+}
+
+if [ $forecast = 0 ]
+then
+ if [ -n "$sunrise" ]
+ then
+ sunrise_time=$(epoch_to_time $sunrise)
+ fi
+
+ if [ -n "$sunset" ]
+ then
+ sunset_time=$(epoch_to_time $sunset)
+ fi
+fi
+
+
+
###[ Set the period ]##########################################################
now=$(date +%s)
@@ -321,5 +355,14 @@ then
output="$output\033[0m"
echo -e "$output"
else
- echo -e "$background$text $greeting_text $city $delimiter$data $temperature $scale $icon$dashes$text $wind_text $delimiter$data $wind $speed_unit $direction $dashes$text $humidity_text $delimiter$data $humidity % $dashes$text $pressure_text $delimiter$data $pressure $pressure_unit \033[0m"
+ output="$background$text $greeting_text $city $delimiter$data $temperature $scale $icon$dashes$text $wind_text $delimiter$data $wind $speed_unit $direction $dashes$text $humidity_text $delimiter$data $humidity % $dashes$text $pressure_text $delimiter$data $pressure $pressure_unit"
+
+ if [ $daylight = true ]
+ then
+ output="$output $dashes$text $sunrise_text $delimiter$data $sunrise_time $dashes$text $sunset_text $delimiter$data $sunset_time"
+ fi
+
+ output="$output \033[0m"
+
+ echo -e "$output"
fi
diff --git a/ansiweatherrc.example b/ansiweatherrc.example
@@ -5,6 +5,7 @@ fetch_cmd:curl -s
units:metric
symbols:true
forecast:0
+daylight:true
# Text and Colors
background:\033[44m
@@ -16,6 +17,8 @@ greeting_text:Current weather in
wind_text:Wind
humidity_text:Humidity
pressure_text:Pressure
+sunrise_text:Sunrise
+sunset_text:Sunset
# Icons
sun:\033[33;1m\xe2\x98\x80