From ae8a57afdc8d71dfa86f62c716bf65d9252ae8df Mon Sep 17 00:00:00 2001 From: Aaron Fordham Date: Thu, 10 Sep 2015 12:05:29 +0000 Subject: [PATCH 1/5] Adding moon phase module --- i3pystatus/moon.py | 133 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 133 insertions(+) create mode 100644 i3pystatus/moon.py diff --git a/i3pystatus/moon.py b/i3pystatus/moon.py new file mode 100644 index 0000000..ef11007 --- /dev/null +++ b/i3pystatus/moon.py @@ -0,0 +1,133 @@ +from i3pystatus import IntervalModule, formatp + +import datetime +import math +import decimal +#import ephem +import os +from i3pystatus.core.util import TimeWrapper + + +dec = decimal.Decimal + +# Moon phase module +class MoonPhase(IntervalModule): + + """ + 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: + } + + + """ + + settings = ( + "format", + ("status", "Current moon phase"), + ("illum", "Percentage that is illuminated"), + ("color", "Set color"), + + ) + + format = "{illum} {status}" + + interval = 60 * 60 * 2 # every 2 hours + + + status = { + + "New Moon": "NM", + "Waxing Crescent": "WaxCres", + "First Quarter": "FQ", + "Waxing Gibbous": "WaxGib", + "Full Moon": "FM", + "Waning Gibbous": "WanGib", + "Last Quarter": "LQ", + "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", + } + + + def pos(now=None): + now = None + days_in_second = 86400 + + if now is None: + now = datetime.datetime.now() + + 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")) + + return lunarCycle % dec(1) + + + def current_phase(self): + + lunarCycle = self.pos() + + index = (lunarCycle * dec(8)) + dec("0.5") + index = math.floor(index) + + return { + 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 + + else: + phase = lunarCycle*2 + + return phase + + def run(self): + + + fdict= { + "status" : self.status[self.current_phase()], + "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()], + } + + From e939d54eaff1eb90a7f76ac147dfa382a3268638 Mon Sep 17 00:00:00 2001 From: Aaron Fordham Date: Thu, 10 Sep 2015 23:41:04 +0000 Subject: [PATCH 2/5] Adding moon phase module --- i3pystatus/moon.py | 186 +++++++++++++++++++++------------------------ 1 file changed, 88 insertions(+), 98 deletions(-) diff --git a/i3pystatus/moon.py b/i3pystatus/moon.py index ef11007..d13177a 100644 --- a/i3pystatus/moon.py +++ b/i3pystatus/moon.py @@ -3,131 +3,121 @@ from i3pystatus import IntervalModule, formatp import datetime import math import decimal -#import ephem import os from i3pystatus.core.util import TimeWrapper - dec = decimal.Decimal + # Moon phase module class MoonPhase(IntervalModule): - """ - 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: - } + """ + Available Formatters + status: Allow for mapping of current moon phase + status { - """ - - settings = ( - "format", - ("status", "Current moon phase"), - ("illum", "Percentage that is illuminated"), - ("color", "Set color"), + New Moon: + Waxing Crescent: + First Quarter: + Waxing Gibbous: + Full Moon: + Waning Gibbous: + 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", - "Waxing Crescent": "WaxCres", - "First Quarter": "FQ", - "Waxing Gibbous": "WaxGib", - "Full Moon": "FM", - "Waning Gibbous": "WanGib", - "Last Quarter": "LQ", - "Waning Cresent": "WanCres", - - } + "New Moon": "NM", + "Waxing Crescent": "WaxCres", + "First Quarter": "FQ", + "Waxing Gibbous": "WaxGib", + "Full Moon": "FM", + "Waning Gibbous": "WanGib", + "Last Quarter": "LQ", + "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): - now = None - days_in_second = 86400 + def pos(now=None): + now = None + days_in_second = 86400 - if now is None: - now = datetime.datetime.now() + if now is None: + now = datetime.datetime.now() - difference = now - datetime.datetime(2001,1,1) - - days = dec(difference.days) + (dec(difference.seconds)/dec(days_in_second)) + difference = now - datetime.datetime(2001, 1, 1) - lunarCycle = dec("0.20439731") + (days * dec("0.03386319269")) - - return lunarCycle % dec(1) + days = dec(difference.days) + (dec(difference.seconds) / dec(days_in_second)) + lunarCycle = dec("0.20439731") + (days * dec("0.03386319269")) - def current_phase(self): + return lunarCycle % dec(1) - lunarCycle = self.pos() - - index = (lunarCycle * dec(8)) + dec("0.5") - index = math.floor(index) + def current_phase(self): - return { - 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: + lunarCycle = self.pos() - phase = 100 - lunarCycle + index = (lunarCycle * dec(8)) + dec("0.5") + index = math.floor(index) - else: - phase = lunarCycle*2 - - return phase - - def run(self): - - - fdict= { - "status" : self.status[self.current_phase()], - "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()], - } + return { + 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 + + 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()], + } From 78d9bdda27391852bfd2ef00b059b9e5a5a02f9b Mon Sep 17 00:00:00 2001 From: Aaron Fordham Date: Fri, 11 Sep 2015 09:13:10 +0000 Subject: [PATCH 3/5] Adding moon phase module --- i3pystatus/moon.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/i3pystatus/moon.py b/i3pystatus/moon.py index d13177a..e049fa9 100644 --- a/i3pystatus/moon.py +++ b/i3pystatus/moon.py @@ -54,6 +54,8 @@ class MoonPhase(IntervalModule): } + color = "#ffffff" + phase_color = { "New Moon": "#00BDE5", "Waxing Crescent": "#138DD8", @@ -112,6 +114,8 @@ class MoonPhase(IntervalModule): def run(self): + color = self.color + fdict = { "status": self.status[self.current_phase()], "illum": self.illum(), From f8223286e058e2ef27b4cde733f2faa51521e5c7 Mon Sep 17 00:00:00 2001 From: Aaron Fordham Date: Fri, 11 Sep 2015 10:32:43 +0000 Subject: [PATCH 4/5] Adding moon phase module --- i3pystatus/moon.py | 193 +++++++++++++++++++++------------------------ 1 file changed, 92 insertions(+), 101 deletions(-) diff --git a/i3pystatus/moon.py b/i3pystatus/moon.py index e049fa9..8e19819 100644 --- a/i3pystatus/moon.py +++ b/i3pystatus/moon.py @@ -2,8 +2,10 @@ from i3pystatus import IntervalModule, formatp import datetime import math + import decimal import os + from i3pystatus.core.util import TimeWrapper dec = decimal.Decimal @@ -11,117 +13,106 @@ dec = decimal.Decimal # Moon phase module class MoonPhase(IntervalModule): + """ + Available Formatters - """ - Available Formatters + status: Allows for mapping of current moon phase to various + - 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: - First Quarter: - Waxing Gibbous: - Full Moon: - Waning Gibbous: - Last Quarter: - Waning Crescent: - } - """ + settings = ( + "format", + ("status", "Current moon phase"), + ("illum", "Percentage that is illuminated"), + ("color", "Set color"), - settings = ( - "format", - ("status", "Current moon phase"), - ("illum", "Percentage that is illuminated"), - ("color", "Set color"), + ) - ) + format = "{illum} {status}" - format = "{illum} {status}" + interval = 60 * 60 * 2 # every 2 hours - interval = 60 * 60 * 2 # every 2 hours + status = { - status = { + "New Moon": "NM", + "Waxing Crescent": "WaxCres", + "First Quarter": "FQ", + "Waxing Gibbous": "WaxGib", + "Full Moon": "FM", + "Waning Gibbous": "WanGib", + "Last Quarter": "LQ", + "Waning Cresent": "WanCres", - "New Moon": "NM", - "Waxing Crescent": "WaxCres", - "First Quarter": "FQ", - "Waxing Gibbous": "WaxGib", - "Full Moon": "FM", - "Waning Gibbous": "WanGib", - "Last Quarter": "LQ", - "Waning Cresent": "WanCres", + } + 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): + days_in_second = 86400 + + now = datetime.datetime.now() + 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")) + + return lunarCycle % dec(1) + + def current_phase(self): + + lunarCycle = self.pos() + + index = (lunarCycle * dec(8)) + dec("0.5") + index = math.floor(index) + + return { + 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 + + else: + phase = lunarCycle * 2 + + return phase + + def run(self): + + fdict = { + "status": self.status[self.current_phase()], + "illum": self.illum(), } - color = "#ffffff" - - 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", + self.output = { + "full_text": formatp(self.format, **fdict), + "color": self.color[self.current_phase()], } - - def pos(now=None): - now = None - days_in_second = 86400 - - if now is None: - now = datetime.datetime.now() - - 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")) - - return lunarCycle % dec(1) - - def current_phase(self): - - lunarCycle = self.pos() - - index = (lunarCycle * dec(8)) + dec("0.5") - index = math.floor(index) - - return { - 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 - - else: - phase = lunarCycle * 2 - - return phase - - def run(self): - - color = self.color - - 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()], - } From a7460dc9e95c92cfc14c15138884816c259c0a33 Mon Sep 17 00:00:00 2001 From: Aaron Fordham Date: Fri, 11 Sep 2015 10:38:14 +0000 Subject: [PATCH 5/5] Adding moon phase module --- i3pystatus/moon.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/i3pystatus/moon.py b/i3pystatus/moon.py index 8e19819..a01fdeb 100644 --- a/i3pystatus/moon.py +++ b/i3pystatus/moon.py @@ -16,7 +16,7 @@ class MoonPhase(IntervalModule): """ Available Formatters - status: Allows for mapping of current moon phase to various + status: Allows for mapping of current moon phase - New Moon: - Waxing Crescent: - First Quarter: