Adding moon phase module

This commit is contained in:
Aaron Fordham 2015-09-11 10:32:43 +00:00
parent 78d9bdda27
commit f8223286e0

View File

@ -2,8 +2,10 @@ from i3pystatus import IntervalModule, formatp
import datetime import datetime
import math import math
import decimal import decimal
import os import os
from i3pystatus.core.util import TimeWrapper from i3pystatus.core.util import TimeWrapper
dec = decimal.Decimal dec = decimal.Decimal
@ -11,22 +13,19 @@ dec = decimal.Decimal
# Moon phase module # Moon phase module
class MoonPhase(IntervalModule): class MoonPhase(IntervalModule):
""" """
Available Formatters Available Formatters
status: Allow for mapping of current moon phase status: Allows for mapping of current moon phase to various
status { - New Moon:
- Waxing Crescent:
- First Quarter:
- Waxing Gibbous:
- Full Moon:
- Waning Gibbous:
- Last Quarter:
- Waning Crescent:
New Moon:
Waxing Crescent:
First Quarter:
Waxing Gibbous:
Full Moon:
Waning Gibbous:
Last Quarter:
Waning Crescent:
}
""" """
settings = ( settings = (
@ -54,9 +53,7 @@ class MoonPhase(IntervalModule):
} }
color = "#ffffff" color = {
phase_color = {
"New Moon": "#00BDE5", "New Moon": "#00BDE5",
"Waxing Crescent": "#138DD8", "Waxing Crescent": "#138DD8",
"First Quarter": "#265ECC", "First Quarter": "#265ECC",
@ -68,16 +65,12 @@ class MoonPhase(IntervalModule):
} }
def pos(now=None): def pos(now=None):
now = None
days_in_second = 86400 days_in_second = 86400
if now is None:
now = datetime.datetime.now() now = datetime.datetime.now()
difference = now - datetime.datetime(2001, 1, 1) difference = now - datetime.datetime(2001, 1, 1)
days = dec(difference.days) + (dec(difference.seconds) / dec(days_in_second)) days = dec(difference.days) + (dec(difference.seconds) / dec(days_in_second))
lunarCycle = dec("0.20439731") + (days * dec("0.03386319269")) lunarCycle = dec("0.20439731") + (days * dec("0.03386319269"))
return lunarCycle % dec(1) return lunarCycle % dec(1)
@ -114,8 +107,6 @@ class MoonPhase(IntervalModule):
def run(self): def run(self):
color = self.color
fdict = { fdict = {
"status": self.status[self.current_phase()], "status": self.status[self.current_phase()],
"illum": self.illum(), "illum": self.illum(),
@ -123,5 +114,5 @@ class MoonPhase(IntervalModule):
self.output = { self.output = {
"full_text": formatp(self.format, **fdict), "full_text": formatp(self.format, **fdict),
"color": self.phase_color[self.current_phase()], "color": self.color[self.current_phase()],
} }