Last active
August 29, 2015 14:08
-
-
Save hanksims/2a146d1a6f641a638754 to your computer and use it in GitHub Desktop.
This file contains 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
import ephem | |
def human_moon(observer): | |
target_date_utc = observer.date | |
target_date_local = ephem.localtime( target_date_utc ).date() | |
next_full = ephem.localtime( ephem.next_full_moon(target_date_utc) ).date() | |
next_new = ephem.localtime( ephem.next_new_moon(target_date_utc) ).date() | |
next_last_quarter = ephem.localtime( ephem.next_last_quarter_moon(target_date_utc) ).date() | |
next_first_quarter = ephem.localtime( ephem.next_first_quarter_moon(target_date_utc) ).date() | |
previous_full = ephem.localtime( ephem.previous_full_moon(target_date_utc) ).date() | |
previous_new = ephem.localtime( ephem.previous_new_moon(target_date_utc) ).date() | |
previous_last_quarter = ephem.localtime( ephem.previous_last_quarter_moon(target_date_utc) ).date() | |
previous_first_quarter = ephem.localtime( ephem.previous_first_quarter_moon(target_date_utc) ).date() | |
if target_date_local in (next_full, previous_full): | |
return 'Full' | |
elif target_date_local in (next_new, previous_new ): | |
return 'New' | |
elif target_date_local in (next_first_quarter, previous_first_quarter): | |
return 'First Quarter' | |
elif target_date_local in (next_last_quarter, previous_last_quarter): | |
return 'Last Full Quarter' | |
elif previous_new < next_first_quarter < next_full < next_last_quarter < next_new: | |
return 'Waxing Crescent' | |
elif previous_first_quarter < next_full < next_last_quarter < next_new < next_first_quarter: | |
return 'Waxing Gibbous' | |
elif previous_full < next_last_quarter < next_new < next_first_quarter < next_full: | |
return 'Waning Gibbous' | |
elif previous_last_quarter < next_new < next_first_quarter < next_full < next_last_quarter: | |
return 'Waning Crescent' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment