Adding moon phase module
This commit is contained in:
parent
ae8a57afdc
commit
e939d54eaf
@ -3,13 +3,12 @@ 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):
|
||||||
|
|
||||||
@ -28,8 +27,6 @@ class MoonPhase(IntervalModule):
|
|||||||
Last Quarter:
|
Last Quarter:
|
||||||
Waning Crescent:
|
Waning Crescent:
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
settings = (
|
settings = (
|
||||||
@ -44,7 +41,6 @@ class MoonPhase(IntervalModule):
|
|||||||
|
|
||||||
interval = 60 * 60 * 2 # every 2 hours
|
interval = 60 * 60 * 2 # every 2 hours
|
||||||
|
|
||||||
|
|
||||||
status = {
|
status = {
|
||||||
|
|
||||||
"New Moon": "NM",
|
"New Moon": "NM",
|
||||||
@ -69,7 +65,6 @@ class MoonPhase(IntervalModule):
|
|||||||
"Waning Crescent": "#FF341F",
|
"Waning Crescent": "#FF341F",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
def pos(now=None):
|
def pos(now=None):
|
||||||
now = None
|
now = None
|
||||||
days_in_second = 86400
|
days_in_second = 86400
|
||||||
@ -77,15 +72,14 @@ class MoonPhase(IntervalModule):
|
|||||||
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))
|
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)
|
||||||
|
|
||||||
|
|
||||||
def current_phase(self):
|
def current_phase(self):
|
||||||
|
|
||||||
lunarCycle = self.pos()
|
lunarCycle = self.pos()
|
||||||
@ -106,28 +100,24 @@ class MoonPhase(IntervalModule):
|
|||||||
|
|
||||||
def illum(self):
|
def illum(self):
|
||||||
phase = 0
|
phase = 0
|
||||||
lunarCycle = float(self.pos())*100
|
lunarCycle = float(self.pos()) * 100
|
||||||
|
|
||||||
if lunarCycle > 50:
|
if lunarCycle > 50:
|
||||||
|
|
||||||
phase = 100 - lunarCycle
|
phase = 100 - lunarCycle
|
||||||
|
|
||||||
else:
|
else:
|
||||||
phase = lunarCycle*2
|
phase = lunarCycle * 2
|
||||||
|
|
||||||
return phase
|
return phase
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
|
|
||||||
|
fdict = {
|
||||||
fdict= {
|
"status": self.status[self.current_phase()],
|
||||||
"status" : self.status[self.current_phase()],
|
"illum": self.illum(),
|
||||||
"illum" : self.illum(),
|
|
||||||
#"phase_color": self.phase_color[self.current_phase()],
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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.phase_color[self.current_phase()],
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user