API & Client - remove DarkSky weather provider
This commit is contained in:
@ -1,37 +0,0 @@
|
||||
from datetime import datetime
|
||||
from typing import Dict, Optional
|
||||
|
||||
import forecastio
|
||||
import pytz
|
||||
|
||||
from .base_weather import BaseWeather
|
||||
|
||||
|
||||
class DarkSky(BaseWeather):
|
||||
# Deprecated (API will end on March 31st, 2023)
|
||||
|
||||
def _get_data(
|
||||
self, latitude: float, longitude: float, time: datetime
|
||||
) -> Optional[Dict]:
|
||||
# get point time in UTC
|
||||
point_time = (
|
||||
pytz.utc.localize(time)
|
||||
if time.tzinfo is None # naive datetime
|
||||
else time
|
||||
)
|
||||
|
||||
forecast = forecastio.load_forecast(
|
||||
self.api_key,
|
||||
latitude,
|
||||
longitude,
|
||||
time=point_time,
|
||||
units='si',
|
||||
)
|
||||
weather = forecast.currently()
|
||||
return {
|
||||
'humidity': weather.humidity,
|
||||
'icon': weather.icon,
|
||||
'temperature': weather.temperature,
|
||||
'wind': weather.windSpeed,
|
||||
'windBearing': weather.windBearing,
|
||||
}
|
@ -5,14 +5,12 @@ from gpxpy.gpx import GPXTrackPoint
|
||||
|
||||
from fittrackee import appLog
|
||||
|
||||
from .dark_sky import DarkSky
|
||||
from .visual_crossing import VisualCrossing
|
||||
|
||||
|
||||
class WeatherService:
|
||||
"""
|
||||
Available API:
|
||||
- DarkSky (deprecated, will end on March 31st, 2023)
|
||||
- VisualCrossing
|
||||
"""
|
||||
|
||||
@ -20,7 +18,7 @@ class WeatherService:
|
||||
self.weather_api = self._get_weather_api()
|
||||
|
||||
@staticmethod
|
||||
def _get_weather_api() -> Union[DarkSky, VisualCrossing, None]:
|
||||
def _get_weather_api() -> Union[VisualCrossing, None]:
|
||||
weather_api_key: str = os.getenv('WEATHER_API_KEY', '')
|
||||
weather_api_provider: str = os.getenv(
|
||||
'WEATHER_API_PROVIDER', ''
|
||||
@ -28,8 +26,6 @@ class WeatherService:
|
||||
|
||||
if not weather_api_key:
|
||||
return None
|
||||
if weather_api_provider == 'darksky': # deprecated
|
||||
return DarkSky(weather_api_key)
|
||||
if weather_api_provider == 'visualcrossing':
|
||||
return VisualCrossing(weather_api_key)
|
||||
return None
|
||||
|
Reference in New Issue
Block a user