Created
December 21, 2016 18:06
-
-
Save raylee/a2bf60546a4374f83507ca77fe448a0e to your computer and use it in GitHub Desktop.
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
# The below is a tiny example using 'astral', a Python module which calculates sun and moon event times. | |
# see its documentation at http://pythonhosted.org/astral/ . This example calculates the length of a day | |
# for 12/2016, at San Luis Obispo, CA, elevation 100. | |
# `pip install astral` will install the dependency | |
from astral import * | |
from datetime import date | |
a = Astral() | |
location = Location(info = ('San Luis Obispo', 'California', 35.27873, -120.65792, 'America/Los_Angeles', 100)) | |
location.timezone = 'America/Los_Angeles' | |
print('Information for %s' % location.name) | |
timezone = location.timezone | |
print('Timezone: %s' % timezone) | |
print('Latitude: %.02f; Longitude: %.02f' % (location.latitude, location.longitude)) | |
year = 2016 | |
for month in [12]: | |
for day in range(1,32): | |
sun = location.sun(local=True, date=date(year, month, day)) | |
sunrise = sun['sunrise'] | |
sunset = sun['sunset'] | |
daylength = sunset - sunrise | |
print('%d/%d/%d\tSunrise: %s\tSunset: %s\tDay Length: %s' % ( | |
month, day, year, sunrise.strftime('%X'), sunset.strftime('%X'), daylength)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment