Last active
October 2, 2021 18:02
-
-
Save webghostx/bc8e982706eaa8ccd113db9340a749be to your computer and use it in GitHub Desktop.
simple Day/Night detection in Python
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/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!' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Ganz wichtig ist die Koordinaten in Strings zu packen. Sonst erscheinen Meldungen wie diese:
usysto.net