new status line functions: moonphase, moonday

This commit is contained in:
Igor Chubin 2018-11-02 18:52:42 +01:00
parent 9f0f9baa32
commit 0d76ba4a3e
2 changed files with 27 additions and 1 deletions

View File

@ -15,6 +15,8 @@ Initial implementation of one-line output mode.
import sys
import re
import datetime
from astral import Astral
from constants import WWO_CODE, WEATHER_SYMBOL, WIND_DIRECTION
from weather_data import get_weather_data
@ -25,6 +27,10 @@ PRECONFIGURED_FORMAT = {
'4': u'%l: %c 🌡️%t 🌬️%w',
}
MOON_PHASES = (
u"🌑", u"🌒", u"🌓", u"🌔", u"🌕", u"🌖", u"🌗", u"🌘"
)
def render_temperature(data):
"""
temperature (t)
@ -74,11 +80,30 @@ def render_location(data):
return data['location'].title()
def render_moonphase(_):
"""
A symbol describing the phase of the moon
"""
astral = Astral()
moon_index = int(
int(32.0*astral.moon_phase(date=datetime.datetime.today())/28+2)%32/4
)
return MOON_PHASES[moon_index]
def render_moonday(_):
"""
An number describing the phase of the moon (days after the New Moon)
"""
astral = Astral()
return str(int(astral.moon_phase(date=datetime.datetime.today())))
FORMAT_SYMBOL = {
'c': render_condition,
't': render_temperature,
'w': render_wind,
'l': render_location,
'm': render_moonphase,
'M': render_moonday,
}
def render_line(line, data):
@ -101,7 +126,7 @@ def render_line(line, data):
render_function = FORMAT_SYMBOL[symbol]
return render_function(data)
return re.sub(r'%[^%]*[a-z]', render_symbol, line)
return re.sub(r'%[^%]*[a-zA-Z]', render_symbol, line)
def format_weather_data(format_line, location, data):
"""

View File

@ -6,3 +6,4 @@ gevent
dnspython
pylint
cyrtranslit
astral