Create a gist now

Instantly share code, notes, and snippets.

Embed
simple Day/Night detection in Python
#!/usr/bin/python
# -- coding: utf-8 --
'''
simple Day/Night detection in Python
require pyephem https://pypi.python.org/pypi/pyephem/
'''
import ephem
import time
run = True
def main():
home = ephem.Observer()
home.lat = '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")
else:
print("It's night")
time.sleep(2)
if __name__ == "__main__":
try:
main()
except KeyboardInterrupt:
print '...stopped!'
@webghostx

This comment has been minimized.

Show comment
Hide comment
@webghostx

webghostx 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

usysto.net

Owner

webghostx 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

usysto.net

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment