-
-
Save mschmitt/58159734183423e565b70cdf90475557 to your computer and use it in GitHub Desktop.
day/night detection for cron jobs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Run every minute and do things IF NOT night. | |
* * * * * (is_night || do_things) >/dev/null 2>&1 | |
# Run every hour and do things IF night. | |
0 * * * * (is_night && do_things) >/dev/null 2>&1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python3 | |
import ephem | |
import time | |
import sys | |
home = ephem.Observer() | |
home.lat = '50.5' | |
home.lon = '8.7' | |
next_sunrise = home.next_rising(ephem.Sun()).datetime() | |
next_sunset = home.next_setting(ephem.Sun()).datetime() | |
if next_sunset < next_sunrise: | |
print("NOT NIGHT rc=1") | |
sys.exit(1) | |
else: | |
print("NIGHT rc=0") | |
sys.exit(0) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment