| 12345678910111213141516171819202122232425262728293031323334353637 |
- #!/usr/bin/env python
- # -*- coding: utf-8 -*-
- import math, decimal, datetime
- def position(time=None):
- dec = decimal.Decimal
- if time is None:
- time = datetime.datetime.now()
- diff = time - datetime.datetime(2001, 1, 1)
- days = dec(diff.days) + (dec(diff.seconds) / dec(86400))
- lunations = dec("0.20439731") + (days * dec("0.03386319269"))
- return lunations % dec(1)
- def phase(pos = None, time = None) -> dict:
- if time is None:
- time = datetime.datetime.now()
- if pos is None:
- pos = position(time)
- dec = decimal.Decimal
- index = (pos * dec(8)) + dec("0.5")
- index = math.floor(index)
- return {
- "index" : index,
- "phase" : int(index) & 7,
- "pos" : pos,
- "name" : {
- 0: "New Moon",
- 1: "Waxing Crescent",
- 2: "First Quarter",
- 3: "Waxing Gibbous",
- 4: "Full Moon",
- 5: "Waning Gibbous",
- 6: "Last Quarter",
- 7: "Waning Crescent"
- }[int(index) & 7]
- }
-
|