weather_wrapper.sh
1 #!/usr/bin/env bash 2 # setting the locale, some users have issues with different locales, this forces the correct one 3 export LC_ALL=en_US.UTF-8 4 5 #wrapper script for running weather on interval 6 7 fahrenheit=$1 8 location=$2 9 fixedlocation=$3 10 11 DATAFILE=/tmp/.dracula-tmux-data 12 LAST_EXEC_FILE="/tmp/.dracula-tmux-weather-last-exec" 13 RUN_EACH=1200 14 TIME_NOW=$(date +%s) 15 TIME_LAST=$(cat "${LAST_EXEC_FILE}" 2>/dev/null || echo "0") 16 17 main() 18 { 19 current_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" 20 21 if [ "$(expr ${TIME_LAST} + ${RUN_EACH})" -lt "${TIME_NOW}" ]; then 22 # Run weather script here 23 $current_dir/weather.sh $fahrenheit $location "$fixedlocation" > "${DATAFILE}" 24 echo "${TIME_NOW}" > "${LAST_EXEC_FILE}" 25 fi 26 27 cat "${DATAFILE}" 28 } 29 30 #run main driver function 31 main