You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

27 lines
617 B

  1. #!/usr/bin/env python3
  2. import envbash
  3. import ephem
  4. import time
  5. import sys
  6. import os
  7. from envbash import load_envbash
  8. # load bash environment vars
  9. load_envbash('/home/pi/.noaa.conf')
  10. tz_offset = int(os.environ['TZ_OFFSET'])
  11. lat = float(os.environ['LAT'])
  12. lon = float(os.environ['LON'])
  13. timezone = (tz_offset * -1) + time.localtime().tm_isdst
  14. date = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(int(sys.argv[1])-(timezone*60*60)))
  15. obs=ephem.Observer()
  16. obs.lat = lat
  17. obs.long = lon
  18. obs.date = date
  19. sun = ephem.Sun(obs)
  20. sun.compute(obs)
  21. sun_angle = float(sun.alt) * 57.2957795 # Rad to deg
  22. print(int(sun_angle))