switched to new astral version
This commit is contained in:
parent
ac1be8305b
commit
b98d919d3c
1 changed files with 13 additions and 20 deletions
33
lib/spark.py
33
lib/spark.py
|
|
@ -26,20 +26,16 @@ import re
|
||||||
import math
|
import math
|
||||||
import json
|
import json
|
||||||
import datetime
|
import datetime
|
||||||
try:
|
import io
|
||||||
import StringIO
|
|
||||||
except:
|
|
||||||
import io as StringIO
|
|
||||||
|
|
||||||
import requests
|
import requests
|
||||||
import diagram
|
import diagram
|
||||||
import pyjq
|
import pyjq
|
||||||
import pytz
|
import pytz
|
||||||
import numpy as np
|
import numpy as np
|
||||||
try:
|
from astral import LocationInfo
|
||||||
from astral import Astral, Location
|
from astral import moon
|
||||||
except ImportError:
|
from astral.sun import sun
|
||||||
pass
|
|
||||||
from scipy.interpolate import interp1d
|
from scipy.interpolate import interp1d
|
||||||
from babel.dates import format_datetime
|
from babel.dates import format_datetime
|
||||||
|
|
||||||
|
|
@ -241,10 +237,7 @@ def draw_time(geo_data):
|
||||||
def draw_astronomical(city_name, geo_data):
|
def draw_astronomical(city_name, geo_data):
|
||||||
datetime_day_start = datetime.datetime.now().replace(hour=0, minute=0, second=0, microsecond=0)
|
datetime_day_start = datetime.datetime.now().replace(hour=0, minute=0, second=0, microsecond=0)
|
||||||
|
|
||||||
a = Astral()
|
city = LocationInfo()
|
||||||
a.solar_depression = 'civil'
|
|
||||||
|
|
||||||
city = Location()
|
|
||||||
city.latitude = geo_data["latitude"]
|
city.latitude = geo_data["latitude"]
|
||||||
city.longitude = geo_data["longitude"]
|
city.longitude = geo_data["longitude"]
|
||||||
city.timezone = geo_data["timezone"]
|
city.timezone = geo_data["timezone"]
|
||||||
|
|
@ -256,12 +249,12 @@ def draw_astronomical(city_name, geo_data):
|
||||||
current_date = (
|
current_date = (
|
||||||
datetime_day_start
|
datetime_day_start
|
||||||
+ datetime.timedelta(hours=1*time_interval)).replace(tzinfo=pytz.timezone(geo_data["timezone"]))
|
+ datetime.timedelta(hours=1*time_interval)).replace(tzinfo=pytz.timezone(geo_data["timezone"]))
|
||||||
sun = city.sun(date=current_date, local=False)
|
current_sun = sun(city.observer, date=current_date)
|
||||||
|
|
||||||
dawn = sun['dawn'] # .replace(tzinfo=None)
|
dawn = current_sun['dawn'] # .replace(tzinfo=None)
|
||||||
dusk = sun['dusk'] # .replace(tzinfo=None)
|
dusk = current_sun['dusk'] # .replace(tzinfo=None)
|
||||||
sunrise = sun['sunrise'] # .replace(tzinfo=None)
|
sunrise = current_sun['sunrise'] # .replace(tzinfo=None)
|
||||||
sunset = sun['sunset'] # .replace(tzinfo=None)
|
sunset = current_sun['sunset'] # .replace(tzinfo=None)
|
||||||
|
|
||||||
if current_date < dawn:
|
if current_date < dawn:
|
||||||
char = " "
|
char = " "
|
||||||
|
|
@ -278,7 +271,7 @@ def draw_astronomical(city_name, geo_data):
|
||||||
|
|
||||||
# moon
|
# moon
|
||||||
if time_interval % 3 == 0:
|
if time_interval % 3 == 0:
|
||||||
moon_phase = city.moon_phase(
|
moon_phase = moon.phase(
|
||||||
date=datetime_day_start + datetime.timedelta(hours=time_interval))
|
date=datetime_day_start + datetime.timedelta(hours=time_interval))
|
||||||
moon_phase_emoji = constants.MOON_PHASES[int(math.floor(moon_phase*1.0/28.0*8+0.5)) % len(constants.MOON_PHASES)]
|
moon_phase_emoji = constants.MOON_PHASES[int(math.floor(moon_phase*1.0/28.0*8+0.5)) % len(constants.MOON_PHASES)]
|
||||||
if time_interval in [0, 24, 48, 69]:
|
if time_interval in [0, 24, 48, 69]:
|
||||||
|
|
@ -454,7 +447,7 @@ def textual_information(data_parsed, geo_data, config):
|
||||||
return output
|
return output
|
||||||
|
|
||||||
|
|
||||||
city = Location()
|
city = LocationInfo()
|
||||||
city.latitude = geo_data["latitude"]
|
city.latitude = geo_data["latitude"]
|
||||||
city.longitude = geo_data["longitude"]
|
city.longitude = geo_data["longitude"]
|
||||||
city.timezone = geo_data["timezone"]
|
city.timezone = geo_data["timezone"]
|
||||||
|
|
@ -464,7 +457,7 @@ def textual_information(data_parsed, geo_data, config):
|
||||||
|
|
||||||
datetime_day_start = datetime.datetime.now()\
|
datetime_day_start = datetime.datetime.now()\
|
||||||
.replace(hour=0, minute=0, second=0, microsecond=0)
|
.replace(hour=0, minute=0, second=0, microsecond=0)
|
||||||
sun = city.sun(date=datetime_day_start, local=True)
|
current_sun = sun(city.observer, date=datetime_day_start)
|
||||||
|
|
||||||
format_line = "%c %C, %t, %h, %w, %P"
|
format_line = "%c %C, %t, %h, %w, %P"
|
||||||
current_condition = data_parsed['data']['current_condition'][0]
|
current_condition = data_parsed['data']['current_condition'][0]
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue