Adding moon phase module
This commit is contained in:
parent
ae8a57afdc
commit
e939d54eaf
@ -3,131 +3,121 @@ from i3pystatus import IntervalModule, formatp
|
|||||||
import datetime
|
import datetime
|
||||||
import math
|
import math
|
||||||
import decimal
|
import decimal
|
||||||
#import ephem
|
|
||||||
import os
|
import os
|
||||||
from i3pystatus.core.util import TimeWrapper
|
from i3pystatus.core.util import TimeWrapper
|
||||||
|
|
||||||
|
|
||||||
dec = decimal.Decimal
|
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 {
|
|
||||||
|
|
||||||
New Moon:
|
|
||||||
Waxing Crescent:
|
|
||||||
First Quarter:
|
|
||||||
Waxing Gibbous:
|
|
||||||
Full Moon:
|
|
||||||
Waning Gibbous:
|
|
||||||
Last Quarter:
|
|
||||||
Waning Crescent:
|
|
||||||
}
|
|
||||||
|
|
||||||
|
status: Allow for mapping of current moon phase
|
||||||
|
status {
|
||||||
|
|
||||||
"""
|
New Moon:
|
||||||
|
Waxing Crescent:
|
||||||
settings = (
|
First Quarter:
|
||||||
"format",
|
Waxing Gibbous:
|
||||||
("status", "Current moon phase"),
|
Full Moon:
|
||||||
("illum", "Percentage that is illuminated"),
|
Waning Gibbous:
|
||||||
("color", "Set color"),
|
Last Quarter:
|
||||||
|
Waning Crescent:
|
||||||
|
}
|
||||||
|
"""
|
||||||
|
|
||||||
)
|
settings = (
|
||||||
|
"format",
|
||||||
|
("status", "Current moon phase"),
|
||||||
|
("illum", "Percentage that is illuminated"),
|
||||||
|
("color", "Set color"),
|
||||||
|
|
||||||
format = "{illum} {status}"
|
)
|
||||||
|
|
||||||
interval = 60 * 60 * 2 # every 2 hours
|
format = "{illum} {status}"
|
||||||
|
|
||||||
|
interval = 60 * 60 * 2 # every 2 hours
|
||||||
|
|
||||||
status = {
|
status = {
|
||||||
|
|
||||||
"New Moon": "NM",
|
"New Moon": "NM",
|
||||||
"Waxing Crescent": "WaxCres",
|
"Waxing Crescent": "WaxCres",
|
||||||
"First Quarter": "FQ",
|
"First Quarter": "FQ",
|
||||||
"Waxing Gibbous": "WaxGib",
|
"Waxing Gibbous": "WaxGib",
|
||||||
"Full Moon": "FM",
|
"Full Moon": "FM",
|
||||||
"Waning Gibbous": "WanGib",
|
"Waning Gibbous": "WanGib",
|
||||||
"Last Quarter": "LQ",
|
"Last Quarter": "LQ",
|
||||||
"Waning Cresent": "WanCres",
|
"Waning Cresent": "WanCres",
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
phase_color = {
|
}
|
||||||
"New Moon": "#00BDE5",
|
|
||||||
"Waxing Crescent": "#138DD8",
|
|
||||||
"First Quarter": "#265ECC",
|
|
||||||
"Waxing Gibbous": "#392FBF",
|
|
||||||
"Full Moon": "#4C00B3",
|
|
||||||
"Waning Gibbous": "#871181",
|
|
||||||
"Last Quarter": "#C32250",
|
|
||||||
"Waning Crescent": "#FF341F",
|
|
||||||
}
|
|
||||||
|
|
||||||
|
phase_color = {
|
||||||
|
"New Moon": "#00BDE5",
|
||||||
|
"Waxing Crescent": "#138DD8",
|
||||||
|
"First Quarter": "#265ECC",
|
||||||
|
"Waxing Gibbous": "#392FBF",
|
||||||
|
"Full Moon": "#4C00B3",
|
||||||
|
"Waning Gibbous": "#871181",
|
||||||
|
"Last Quarter": "#C32250",
|
||||||
|
"Waning Crescent": "#FF341F",
|
||||||
|
}
|
||||||
|
|
||||||
def pos(now=None):
|
def pos(now=None):
|
||||||
now = None
|
now = None
|
||||||
days_in_second = 86400
|
days_in_second = 86400
|
||||||
|
|
||||||
if now is None:
|
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))
|
|
||||||
|
|
||||||
lunarCycle = dec("0.20439731") + (days * dec("0.03386319269"))
|
days = dec(difference.days) + (dec(difference.seconds) / dec(days_in_second))
|
||||||
|
|
||||||
return lunarCycle % dec(1)
|
|
||||||
|
|
||||||
|
lunarCycle = dec("0.20439731") + (days * dec("0.03386319269"))
|
||||||
|
|
||||||
def current_phase(self):
|
return lunarCycle % dec(1)
|
||||||
|
|
||||||
lunarCycle = self.pos()
|
def current_phase(self):
|
||||||
|
|
||||||
index = (lunarCycle * dec(8)) + dec("0.5")
|
|
||||||
index = math.floor(index)
|
|
||||||
|
|
||||||
return {
|
lunarCycle = self.pos()
|
||||||
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]
|
|
||||||
|
|
||||||
def illum(self):
|
|
||||||
phase = 0
|
|
||||||
lunarCycle = float(self.pos())*100
|
|
||||||
|
|
||||||
if lunarCycle > 50:
|
|
||||||
|
|
||||||
phase = 100 - lunarCycle
|
index = (lunarCycle * dec(8)) + dec("0.5")
|
||||||
|
index = math.floor(index)
|
||||||
|
|
||||||
else:
|
return {
|
||||||
phase = lunarCycle*2
|
0: "New Moon",
|
||||||
|
1: "Waxing Crescent",
|
||||||
return phase
|
2: "First Quarter",
|
||||||
|
3: "Waxing Gibbous",
|
||||||
def run(self):
|
4: "Full Moon",
|
||||||
|
5: "Waning Gibbous",
|
||||||
|
6: "Last Quarter",
|
||||||
fdict= {
|
7: "Waning Crescent",
|
||||||
"status" : self.status[self.current_phase()],
|
}[int(index) & 7]
|
||||||
"illum" : self.illum(),
|
|
||||||
#"phase_color": self.phase_color[self.current_phase()],
|
|
||||||
}
|
|
||||||
self.output = {
|
|
||||||
"full_text": formatp(self.format,**fdict),
|
|
||||||
"color": self.phase_color[self.current_phase()],
|
|
||||||
}
|
|
||||||
|
|
||||||
|
def illum(self):
|
||||||
|
phase = 0
|
||||||
|
lunarCycle = float(self.pos()) * 100
|
||||||
|
|
||||||
|
if lunarCycle > 50:
|
||||||
|
phase = 100 - lunarCycle
|
||||||
|
|
||||||
|
else:
|
||||||
|
phase = lunarCycle * 2
|
||||||
|
|
||||||
|
return phase
|
||||||
|
|
||||||
|
def run(self):
|
||||||
|
|
||||||
|
fdict = {
|
||||||
|
"status": self.status[self.current_phase()],
|
||||||
|
"illum": self.illum(),
|
||||||
|
}
|
||||||
|
|
||||||
|
self.output = {
|
||||||
|
"full_text": formatp(self.format, **fdict),
|
||||||
|
"color": self.phase_color[self.current_phase()],
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user