Refactored almanac.py for Python 3

This commit is contained in:
Tom Keffer
2019-02-06 06:51:26 -08:00
parent 01f46f3966
commit 7234f9bd04

View File

@@ -8,7 +8,6 @@
This module can optionally use PyEphem, which offers high quality
astronomical calculations. See http://rhodesmill.org/pyephem. """
from __future__ import print_function
import time
import sys
import math
@@ -83,23 +82,23 @@ class Almanac(object):
Fullness of the moon (more precise) is 1.70%
Test backwards compatibility with attributes 'sunrise' and 'sunset'
>>> print("Sunrise, sunset:", almanac.sunrise, almanac.sunset)
>>> print("Sunrise, sunset: %s %s" % (almanac.sunrise, almanac.sunset))
Sunrise, sunset: 06:56 19:30
Get sunrise, sun transit, and sunset using the new 'ephem' syntax:
>>> print("Sunrise, sun transit, sunset:", almanac.sun.rise, almanac.sun.transit, almanac.sun.set)
>>> print("Sunrise, sun transit, sunset: %s %s %s" % (almanac.sun.rise, almanac.sun.transit, almanac.sun.set))
Sunrise, sun transit, sunset: 06:56 13:13 19:30
Do the same with the moon:
>>> print("Moon rise, transit, set:", almanac.moon.rise, almanac.moon.transit, almanac.moon.set)
>>> print("Moon rise, transit, set: %s %s %s" % (almanac.moon.rise, almanac.moon.transit, almanac.moon.set))
Moon rise, transit, set: 06:59 14:01 21:20
And Mars
>>> print("Mars rise, transit, set:", almanac.mars.rise, almanac.mars.transit, almanac.mars.set)
>>> print("Mars rise, transit, set: %s %s %s" % (almanac.mars.rise, almanac.mars.transit, almanac.mars.set))
Mars rise, transit, set: 06:08 11:34 17:00
Finally, try a star
>>> print("Rigel rise, transit, set:", almanac.rigel.rise, almanac.rigel.transit, almanac.rigel.set)
>>> print("Rigel rise, transit, set: %s %s %s" % (almanac.rigel.rise, almanac.rigel.transit, almanac.rigel.set))
Rigel rise, transit, set: 12:32 18:00 23:28
Exercise sidereal time