+ Calculate the approximate times of full darkness for the
+ next day, so we can set the schedule for the webcam. For the
+ current location, pictures taken at night are not that
+ interesting and don't vary from one night to the next, so
+ I'll turn the camera off when it gets dark and turn it on
+ in the morning when it starts getting light.
+ Civil twilight is defined as the Sun being 6° below the
+ horizon. From examining images, it looks like choosing
+ 7° is a good choice for me.
+from __future__ import print_function
+os.environ['DJANGO_SETTINGS_MODULE'] = 'web.settings'
+from pics.models import Location
+from django.utils.timezone import utc
+# Choose defaults from the environment.
+# I set these defaults in the postactivate script of the virtualenv
+location = Location.objects.get(pk=os.environ['TIMELAPSE_LOCATION_ID'])
+observer = ephem.Observer()
+observer.lat = str(location.latitude)
+observer.lon = str(location.longitude)
+observer.elevation = location.elevation
+observer.date = ephem.now()
+observer.horizon = '-7' # when the webcam looks fully dark
+rising = observer.next_rising(sun, use_center=True)
+setting = observer.next_setting(sun, use_center=True)