Mark Sundstrom committed 3bd55f6 to help with webcam time scheduling

Comments (0)

Files changed (1)

+#!/usr/bin/env python
+# -*- coding: utf8
+    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
+import sys
+import os
+os.environ['DJANGO_SETTINGS_MODULE'] = 'web.settings'
+import datetime
+from pics.models import Location
+import pytz
+from django.utils.timezone import utc
+import ephem
+# 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() = str(location.latitude)
+observer.lon = str(location.longitude)
+observer.elevation = location.elevation =
+observer.horizon = '-7'  # when the webcam looks fully dark
+sun = ephem.Sun()
+rising = observer.next_rising(sun, use_center=True)
+print("Dawn:", ephem.localtime(rising))
+setting = observer.next_setting(sun, use_center=True)
+print("Dusk:", ephem.localtime(setting))