line.py: use new astral lib

This commit is contained in:
Igor Chubin 2020-04-27 19:04:27 +02:00
parent 156ab97cf2
commit 2ef8435b36

View file

@ -17,10 +17,8 @@ import sys
import re import re
import datetime import datetime
import json import json
try:
from astral import Astral, Location from astral import moon
except ImportError:
pass
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
from . import v2 from . import v2
@ -161,26 +159,32 @@ def render_location(data, query):
location (l) location (l)
""" """
return (data['override_location'] or data['location']) # .title() return (data['override_location'] or data['location'])
def render_moonphase(_, query): def render_moonphase(_, query):
""" """moonpahse(m)
A symbol describing the phase of the moon A symbol describing the phase of the moon
""" """
astral = Astral() moon_phase = moon.phase(date=datetime.datetime.today())
moon_index = int( moon_index = int(int(32.0*moon_phase/28+2)%32/4)
int(32.0*astral.moon_phase(date=datetime.datetime.today())/28+2)%32/4
)
return MOON_PHASES[moon_index] return MOON_PHASES[moon_index]
def render_moonday(_, query): def render_moonday(_, query):
""" """moonday(M)
An number describing the phase of the moon (days after the New Moon) An number describing the phase of the moon (days after the New Moon)
""" """
astral = Astral() moon_phase = moon.phase(date=datetime.datetime.today())
return str(int(astral.moon_phase(date=datetime.datetime.today()))) return str(int(moon_phase))
def render_sunset(data, query): def render_sunset(data, query):
"""
sunset (s)
NOT YET IMPLEMENTED
"""
return "%s"
location = data['location'] location = data['location']
city_name = location city_name = location
astral = Astral() astral = Astral()