Reputation: 21
I have a time lapse python script that works fine in the uk, it now I live in France it’s still calculating on standard GMT time. How can I change the code so it represents my actual location?
import sys
import os
import time
import ephem
#find time of sun rise and sunset
sun = ephem.Sun()
home = ephem.Observer()
home.lat, home.lon = '45.226691', '0.013133' #your lat long
sun.compute(home)
sunrise, sunset = (home.next_rising(sun),
home.next_setting(sun))
daylightminutes = (sunset - sunrise) * 1440 # find howmany minutes of daylight there are
daylightminutes = (round(daylightminutes))
sunriselessonemin = ephem.date(sunrise + 1*ephem.minute)
print "prog started at(home.date) = %s" %(home.date)
print "datetime = %s" % time.strftime("%Y/%-m/%-d %H:%M:%S")
print "sunrise = %s" %sunrise
print "sunset = %s" %sunset
print "daylight mins = %s" %(daylightminutes)
....
while ephem.now() <= sunrise:
time.sleep(1)
dostuff()
The code is assuming it’s sunrize/sunset at gmt time rather than my local time despite knowing my actual lat/long. So at the present in France we are 2 hours ahead of gmt, which is no use of course.
Upvotes: 1
Views: 392
Reputation: 89454
PyEphem could not translate lat/lon into a timezone without having a built-in map of world time zone boundaries, which, alas, it does not.
But your computer operating system knows your timezone if you've set it, and PyEphem has a "localtime()" function that will ask the operating system for the time zone to use for printing a time:
https://rhodesmill.org/pyephem/date.html#time-zones
Upvotes: 1