Skip to content

Instantly share code, notes, and snippets.

@stucka
Last active December 20, 2015 17:28
Show Gist options
  • Save stucka/6168508 to your computer and use it in GitHub Desktop.
Save stucka/6168508 to your computer and use it in GitHub Desktop.
Run some code an hour before sunrise.
#!/home/mstucka/bin/python
#Want to do something an hour before sunrise?
#sleep `./hourtosunrise.py`
#./dosomething.sh
import ephem
import datetime
import sys
now=datetime.datetime.now()
Macon=ephem.Observer()
Macon.lat="32.841"
Macon.long="-83.632"
Macon.elevation=116 #meters
sun=ephem.Sun()
sunrise=ephem.localtime(Macon.next_rising(sun))
timetosunrise=(sunrise-now).seconds
sys.stdout.write(str(timetosunrise-3600))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment