Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
simple Day/Night detection in Python
# -- coding: utf-8 --
simple Day/Night detection in Python
require pyephem
import ephem
import time
run = True
def main():
home = ephem.Observer() = '47.17' # str() Latitude
home.lon = '7.37' # str() Longitude
while run:
next_sunrise = home.next_rising(ephem.Sun()).datetime()
next_sunset = home.next_setting(ephem.Sun()).datetime()
if next_sunset < next_sunrise:
print("It's day")
print("It's night")
if __name__ == "__main__":
except KeyboardInterrupt:
print '...stopped!'

This comment has been minimized.

Copy link
Owner Author

commented May 5, 2017

Ganz wichtig ist die Koordinaten in Strings zu packen. Sonst erscheinen Meldungen wie diese:

'Sun' is still above the horizon at 2017/5/5 19:47:34
'Sun' transits below the horizon at 2017/5/6 07:47:32

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.