new status line functions: moonphase, moonday
This commit is contained in:
parent
9f0f9baa32
commit
0d76ba4a3e
2 changed files with 27 additions and 1 deletions
|
|
@ -15,6 +15,8 @@ Initial implementation of one-line output mode.
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
import re
|
import re
|
||||||
|
import datetime
|
||||||
|
from astral import Astral
|
||||||
from constants import WWO_CODE, WEATHER_SYMBOL, WIND_DIRECTION
|
from constants import WWO_CODE, WEATHER_SYMBOL, WIND_DIRECTION
|
||||||
from weather_data import get_weather_data
|
from weather_data import get_weather_data
|
||||||
|
|
||||||
|
|
@ -25,6 +27,10 @@ PRECONFIGURED_FORMAT = {
|
||||||
'4': u'%l: %c 🌡️%t 🌬️%w',
|
'4': u'%l: %c 🌡️%t 🌬️%w',
|
||||||
}
|
}
|
||||||
|
|
||||||
|
MOON_PHASES = (
|
||||||
|
u"🌑", u"🌒", u"🌓", u"🌔", u"🌕", u"🌖", u"🌗", u"🌘"
|
||||||
|
)
|
||||||
|
|
||||||
def render_temperature(data):
|
def render_temperature(data):
|
||||||
"""
|
"""
|
||||||
temperature (t)
|
temperature (t)
|
||||||
|
|
@ -74,11 +80,30 @@ def render_location(data):
|
||||||
|
|
||||||
return data['location'].title()
|
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 = {
|
FORMAT_SYMBOL = {
|
||||||
'c': render_condition,
|
'c': render_condition,
|
||||||
't': render_temperature,
|
't': render_temperature,
|
||||||
'w': render_wind,
|
'w': render_wind,
|
||||||
'l': render_location,
|
'l': render_location,
|
||||||
|
'm': render_moonphase,
|
||||||
|
'M': render_moonday,
|
||||||
}
|
}
|
||||||
|
|
||||||
def render_line(line, data):
|
def render_line(line, data):
|
||||||
|
|
@ -101,7 +126,7 @@ def render_line(line, data):
|
||||||
render_function = FORMAT_SYMBOL[symbol]
|
render_function = FORMAT_SYMBOL[symbol]
|
||||||
return render_function(data)
|
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):
|
def format_weather_data(format_line, location, data):
|
||||||
"""
|
"""
|
||||||
|
|
|
||||||
|
|
@ -6,3 +6,4 @@ gevent
|
||||||
dnspython
|
dnspython
|
||||||
pylint
|
pylint
|
||||||
cyrtranslit
|
cyrtranslit
|
||||||
|
astral
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue