dotfiles

Cem's Dotfiles
git clone git://git.ckyln.com/dotfiles.git
Log | Files | Refs | Submodules | README | LICENSE

commit 74e7bff1be64252401b091f9f9c038c15b1cf721
parent 3b076b113196bba08572d195ee82598584e05967
Author: Cem Keylan <cem@ckyln.com>
Date:   Wed, 26 Jun 2019 12:25:33 +0300

Update Nightmode according to sunset API

Diffstat:
Abin/checksunset | 34++++++++++++++++++++++++++++++++++
Mbin/nightmodetoggle | 5++++-
2 files changed, 38 insertions(+), 1 deletion(-)

diff --git a/bin/checksunset b/bin/checksunset @@ -0,0 +1,34 @@ +#!/bin/sh + +LAT=40.010787 +LON=33.046875 + + +error() {\ + echo "Error: $1" + exit +} + +jq --version >/dev/null 2>&1 || error "You must install jq to continue (https://stedolan.github.io/jq/)" + +[ -e $HOME/.sunset ] || touch $HOME/.sunset +. $HOME/.sunset +[ "$checkdate" = `date +%Y%m%d` ] && exit # Don't check anything if you have already checked today. +ping sunrise-sunset.org -c 1 -W 5 || exit +if [ -z $LAT ] || [ -z $LON ]; then + PUBLIC_IP=`curl -s https://ipinfo.io/ip` + LAT=$(curl -s https://ipvigilante.com/${PUBLIC_IP} | \ + jq '.data.latitude' | \ + cut -c 2- | rev | cut -c 2- | rev ) + LON=$(curl -s https://ipvigilante.com/${PUBLIC_IP} | \ + jq '.data.longitude' | cut -c 2- | rev | cut -c 2- | rev) +fi + + +MORNING=$(date --date="TZ=\"UTC\" $(curl https://api.sunrise-sunset.org/json\?lat\=$LAT\&lng\=$LON\&date\=today | jq .results.sunrise | cut -c 2- | awk '{print $1}')" +%H%M) +NIGHT=$(date -d "$(date --date="TZ=\"UTC\" $(curl https://api.sunrise-sunset.org/json\?lat\=$LAT\&lng\=$LON\&date\=today | jq .results.sunset | cut -c 2- | awk '{print $1}')" +%H:%M) today + 12 hours" +%H%M) + +printf "\ +SUNRISE=$MORNING\n\ +SUNSET=$NIGHT\n\ +checkdate=`date +%Y%m%d`\n" > $HOME/.sunset diff --git a/bin/nightmodetoggle b/bin/nightmodetoggle @@ -26,7 +26,10 @@ then then exit else - if [ `date +%H%M` -gt "1959" ] || [ `date +%H%M` -lt "0600" ] + [ -e $HOME/.sunset ] && . $HOME/.sunset + [ -z $SUNSET ] && SUNSET=1959 + [ -z $SUNRISE ] && SUNRISE=0600 + if [ `date +%H%M` -gt "$SUNSET" ] || [ `date +%H%M` -lt "$SUNRISE" ] then printf "CLICK=0\nNIGHT=1" > $HOME/.night else