dotfiles

regexghost dotfiles and scripts
git clone https://git.regexghost.com/dotfiles.git
Log | Files | Refs | README

sunrise.sh (2728B)


      1 #!/usr/bin/env bash
      2 
      3 # Syntax for current_location.csv:
      4 # `lat|lon`
      5 
      6 curLocationFile="$XDG_CONFIG_HOME/regexghost/current_location.csv"
      7 
      8 lat=$(cat "$curLocationFile" | cut -d "|" -f 1)
      9 lon=$(cat "$curLocationFile" | cut -d "|" -f 2)
     10 
     11 theme=$(cat "$XDG_CONFIG_HOME/regexghost/current-theme.txt")
     12 
     13 if [[ "$theme" == "dracula" ]]; then
     14 	sunsetColour="8be9fd"
     15 	sunriseColour="ffff80"
     16 	goldenHourColour="ffff80"
     17 elif [[ "$theme" == "christmas" ]]; then
     18 	sunsetColour="FD971F"
     19 	sunriseColour="F1C769"
     20 	goldenHourColour="F1C769"
     21 elif [[ "$theme" == "tube" ]]; then
     22 	sunsetColour="e67823"
     23 	sunriseColour="ffd204"
     24 	goldenHourColour="ffd204"
     25 fi
     26 
     27 if [[ "$1" == "--sunrise" ]]; then
     28 	#json_tomorrow=$(curl -s "https://api.sunrisesunset.io/json?lat=${lat}&lng=${lon}&date=tomorrow&time_format=24")
     29 	json_tomorrow=$(curl --connect-timeout 5 -s "https://api.sunrise-sunset.org/json?lat=${lat}&lng=${lon}&date=tomorrow&formatted=0")
     30 	sunrise=$(echo "$json_tomorrow" | jq -r .results.sunrise | sed 's/.*T//g' | sed 's/:[0-9]*+.*//g')
     31 	[ "$sunrise" = "" ] && sunrise="?"
     32 	astro_twilight=$(echo "$json_tomorrow" | jq -r .results.astronomical_twilight_begin | sed 's/.*T//g' | sed 's/:[0-9]*+.*//g')
     33 	if [[ "$2" == "--conky" ]]; then
     34 		echo "\${color #$sunriseColour}$astro_twilight - $sunrise \${color}"
     35 	elif [[ "$2" == "--blank" ]]; then
     36 		echo "$sunrise"
     37 	else
     38 		echo "<span font='Font Awesome 7 Free Solid 9' foreground='#$sunriseColour'> </span> <span foreground='#$sunriseColour'>$astro_twilight - $sunrise </span>"
     39 	fi
     40 elif [[ "$1" == "--sunset" ]]; then
     41 	#json_today=$(curl -s "https://api.sunrisesunset.io/json?lat=${lat}&lng=${lon}&time_format=24")
     42 	json_today=$(curl --connect-timeout 5 -s "https://api.sunrise-sunset.org/json?lat=${lat}&lng=${lon}&date=today&formatted=0")
     43 	sunset=$(echo "$json_today" | jq -r .results.sunset | sed 's/.*T//g' | sed 's/:[0-9]*+.*//g')
     44 	[ "$sunset" = "" ] && sunset="?"
     45 	astro_twilight=$(echo "$json_today" | jq -r .results.astronomical_twilight_end | sed 's/.*T//g' | sed 's/:[0-9]*+.*//g')
     46 	if [[ "$2" == "--conky" ]]; then
     47 		echo "\${color #$sunsetColour}$sunset - $astro_twilight \${color}"
     48 	elif [[ "$2" == "--blank" ]]; then
     49 		echo "$sunset"
     50 	else
     51 		echo "<span font='Font Awesome 7 Free Solid 9' foreground='#$sunsetColour'> </span> <span foreground='#$sunsetColour'>$sunset - $astro_twilight </span>"
     52 	fi
     53 #elif [[ "$1" == "--golden-hour" ]]; then
     54 #	json_today=$(curl -s "https://api.sunrisesunset.io/json?lat=${lat}&lng=${lon}&time_format=24")
     55 #	golden_hour=$(echo "$json_today" | jq -r .results.golden_hour | sed 's/:[0-9]*$//g')
     56 #	echo "<span font='Font Awesome 7 Free Solid 9' foreground='#$goldenHourColour'> </span> <span foreground='#$goldenHourColour'>$golden_hour </span>"
     57 fi
     58 
     59