commit
8692d3e8ca
@ -0,0 +1,79 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Enter your zipcode here for local weather.
|
||||
zipcode=20001
|
||||
|
||||
# Colors are nice
|
||||
blk=$(tput setaf 0)
|
||||
red=$(tput setaf 1)
|
||||
grn=$(tput setaf 2)
|
||||
ylw=$(tput setaf 3)
|
||||
blu=$(tput setaf 4)
|
||||
cyn=$(tput setaf 6)
|
||||
wht=$(tput setaf 7)
|
||||
und=$(tput smul)
|
||||
bld=$(tput bold)
|
||||
# Uncoloring is important
|
||||
rst=$(tput sgr0)
|
||||
# Get the number of columns and rows to center the
|
||||
# last updated time on the bottom of the window.
|
||||
cols=$(tput cols)
|
||||
rows=$(tput lines)
|
||||
|
||||
# trap ctrl-c and call ctrl_c()
|
||||
# https://rimuhosting.com/knowledgebase/linux/misc/trapping-ctrl-c-in-bash
|
||||
trap ctrl_c INT
|
||||
|
||||
function ctrl_c() {
|
||||
clear
|
||||
tput cnorm
|
||||
echo "${rst}${red}CTRL+C Detected, exiting.${rst}"
|
||||
exit
|
||||
}
|
||||
|
||||
function dothething() {
|
||||
# Grab the size of the window again as the window size
|
||||
# may have changed since the script was started.
|
||||
cols=$(tput cols)
|
||||
rows=$(tput lines)
|
||||
clear
|
||||
updatedstring="Last updated: `date \"+%F %X\"`"
|
||||
# Sometimes this may not complete due to wttr.in running
|
||||
# out of available queries to their weather provider.
|
||||
# This should only last for a day or so.
|
||||
curl wttr.in/${zipcode}?1QnuFA
|
||||
# Make sure the updated line is at the bottom of the screen
|
||||
down=$rows
|
||||
# Do some math to center the string horizontally
|
||||
let over="$cols/2-${#updatedstring}/2"
|
||||
# Move the cursor over to the correct starting location
|
||||
tput cup $down $over
|
||||
# Print the last time the weather was updated
|
||||
echo -n "${rst}${ylw}${updatedstring}${rst}"
|
||||
# Reset the cursor back to 0,0
|
||||
tput cup 0 0
|
||||
}
|
||||
|
||||
# Clear the screen and let's get going
|
||||
clear
|
||||
# Make the cursor invisible for the terminal
|
||||
tput civis
|
||||
# Programmers are great at naming things
|
||||
dothething
|
||||
# Loop forever. Use ctrl+c to exit.
|
||||
while true; do
|
||||
# We want to make sure we only check once per hour
|
||||
# in order to not overwhelm the wttr.in service.
|
||||
|
||||
# Octal fix: https://stackoverflow.com/a/24777667
|
||||
if [ `date +%M` -eq "00" ]; then
|
||||
# Don't forget to check the seconds or it'll run
|
||||
# the command every second of the 0th minute.
|
||||
if [ `date +%S` -eq "00" ]; then
|
||||
dothething
|
||||
fi
|
||||
fi
|
||||
# Sleep for a second so we're not hammering the system
|
||||
# with date checks.
|
||||
sleep 1
|
||||
done
|
Loading…
Reference in new issue