Skip to content

Commit

Permalink
Merge branch 'test-revamp-endpoint-additions'
Browse files Browse the repository at this point in the history
  • Loading branch information
John Koelndorfer committed Feb 2, 2021
2 parents b11a586 + 6fd944f commit 0e5055d
Show file tree
Hide file tree
Showing 21 changed files with 432 additions and 145 deletions.
6 changes: 4 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@
/venv
/.pytest_cache
/aerisweather.egg-info
/tests/keys.py
/dist
/AerisWeatherPythonDemo/.idea
/AerisWeatherPythonDemo/venv
/AerisWeatherPythonDemo/keys.py
/AerisWeatherPythonDemo/keys.py
__pycache__
.tox
build/
4 changes: 4 additions & 0 deletions .python-version
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
3.6.12
3.7.9
3.8.7
3.9.1
35 changes: 35 additions & 0 deletions aerisweather/aerisweather.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from aerisweather.requests.RequestQuery import RequestQuery
from aerisweather.requests.RequestSort import RequestSort
from aerisweather.responses.AlertsResponse import AlertsResponse
from aerisweather.responses.ConditionsResponse import ConditionsResponse
from aerisweather.responses.CustomResponse import CustomResponse
from aerisweather.responses.ForecastsResponse import ForecastsResponse
from aerisweather.responses.ObservationsResponse import ObservationsResponse
Expand Down Expand Up @@ -170,6 +171,8 @@ def response(endpoint_type: EndpointType,

if endpoint_type == EndpointType.ALERTS:
return AlertsResponse(response_json)
elif endpoint_type == EndpointType.CONDITIONS:
return ConditionsResponse(response_json)
elif endpoint_type == EndpointType.FORECASTS:
return ForecastsResponse(response_json)
elif endpoint_type == EndpointType.OBSERVATIONS:
Expand Down Expand Up @@ -445,6 +448,38 @@ def alerts(self,

return self.request(endpoint=endpoint)

def conditions(self,
location: RequestLocation = None,
action: RequestAction = None,
filter_: [RequestFilter] = None,
sort: RequestSort = None,
params: Dict[ParameterType, str] = None,
query: Dict[RequestQuery, str] = None):
""" Performs an API request to get conditions data for a specified location.
Params:
- location: Optional - RequestLocation - the location for which the request is processed
- action: Optional - RequestAction - the API request action option
- filter_: Optional - [RequestFilter] - a list of API request filters
- sort: Optional - RequestSort - the API request sort option
- params: Optional - Dict[ParameterType, str] - a list of API request parameters
- query: Optional - Dict[RequestQuery, str] - a list of API request quesries
Returns:
- a list of ConditionsResponse objects if successful
- an empty list if there is no data
"""

endpoint = Endpoint(endpoint_type=EndpointType.CONDITIONS,
location=location,
action=action,
filter_=filter_,
sort=sort,
params=params,
query=query)

return self.request(endpoint=endpoint)

def forecasts(self,
location: RequestLocation = None,
action: RequestAction = None,
Expand Down
1 change: 1 addition & 0 deletions aerisweather/requests/Endpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class EndpointType(Enum):
"""

ALERTS = "advisories"
CONDITIONS = "conditions"
CONVECTIVE_OUTLOOK = "convective/outlook"
FORECASTS = "forecasts"
OBSERVATIONS = "observations"
Expand Down
10 changes: 10 additions & 0 deletions aerisweather/requests/ParameterType.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,16 @@ class ALERTS(Enum):
SKIP = "skip"
SORT = "sort"

@skip
class CONDITIONS(Enum):
P = "p"
FOR = "for"
FROM = "from"
TO = "to"
PLIMIT = "plimit"
PSKIP = "pskip"
PSORT = "psort"

@skip
class FORECASTS(Enum):
CALLBACK = "callback"
Expand Down
6 changes: 6 additions & 0 deletions aerisweather/requests/RequestAction.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ class ALERTS(Enum):
SEARCH = "search"
WITHIN = "within"

@skip
class CONDITIONS(Enum):
ID = "id"
CLOSEST = "closest"
ROUTE = "route"

@skip
class CONVECTIVE_OUTLOOK(Enum):
AFFECTS = "affects"
Expand Down
10 changes: 10 additions & 0 deletions aerisweather/responses/AerisProfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,16 @@ def neighbors(self) -> List[str]:
return neighbors


class AerisProfileConditions(AerisProfile):
"""Defines an object for the Aeris API profile data returned in an Aeris API Conditions responses"""

def __init__(self, json_data):
""" Constructor """

self.data = json_data
super().__init__(self.data)


class AerisProfileFires(AerisProfile):
"""Defines an object for the Aeris API profile data returned in an Aeris API Fires responses"""

Expand Down
189 changes: 189 additions & 0 deletions aerisweather/responses/ConditionsPeriod.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,189 @@
from typing import Optional


class ConditionsPeriod:
"""
Object describing a period from the conditions endpoint.
"""
# A conditions endpoint period takes the form:
#
# {
# "timestamp": 1612215840,
# "dateTimeISO": "2021-02-01T16:44:00-05:00",
# "tempC": 2.58,
# "tempF": 36.64,
# "feelslikeC": -1.26,
# "feelslikeF": 29.74,
# "dewpointC": -3.26,
# "dewpointF": 26.13,
# "humidity": 62,
# "pressureMB": 1014.5,
# "pressureIN": 29.96,
# "windDir": "NW",
# "windDirDEG": 320,
# "windSpeedKTS": 17.95,
# "windSpeedKPH": 33.24,
# "windSpeedMPH": 20.66,
# "windGustKTS": 26.9,
# "windGustKPH": 49.82,
# "windGustMPH": 30.96,
# "precipMM": 0,
# "precipIN": 0,
# "snowCM": 0,
# "snowIN": 0,
# "visibilityKM": 19.911,
# "visibilityMI": 12.372,
# "sky": 95,
# "cloudsCoded": "OV",
# "weather": "Cloudy",
# "weatherCoded": "::OV",
# "weatherPrimary": "Cloudy",
# "weatherPrimaryCoded": "::OV",
# "icon": "cloudy.png",
# "solradWM2": 83,
# "uvi": 0,
# "isDay": true
# }

def __init__(self, data) -> None:
self.data = data

@property
def timestamp(self) -> int:
return self.data["timestamp"]

@property
def dateTimeISO(self) -> str:
return self.data["dateTimeISO"]

@property
def tempC(self) -> Optional[float]:
return self.data["tempC"]

@property
def tempF(self) -> Optional[float]:
return self.data["tempF"]

@property
def feelslikeC(self) -> Optional[float]:
return self.data["feelsLikeC"]

@property
def feelslikeF(self) -> Optional[float]:
return self.data["feelsLikeF"]

@property
def dewpointC(self) -> Optional[float]:
return self.data["dewpointC"]

@property
def dewpointF(self) -> Optional[float]:
return self.data["dewpointF"]

@property
def humidity(self) -> Optional[int]:
return self.data["humidity"]

@property
def pressureMB(self) -> Optional[float]:
return self.data["pressureMB"]

@property
def pressureIN(self) -> Optional[float]:
return self.data["pressureIN"]

@property
def windDir(self) -> Optional[str]:
return self.data["windDir"]

@property
def windDirDEG(self) -> Optional[int]:
return self.data["windDirDEG"]

@property
def windSpeedKTS(self) -> Optional[float]:
return self.data["windSpeedKTS"]

@property
def windSpeedKPH(self) -> Optional[float]:
return self.data["windSpeedKPH"]

@property
def windSpeedMPH(self) -> Optional[float]:
return self.data["windSpeedMPH"]

@property
def windGustKTS(self) -> Optional[float]:
return self.data["windGustKTS"]

@property
def windGustKPH(self) -> Optional[float]:
return self.data["windGustKPH"]

@property
def windGustMPH(self) -> Optional[float]:
return self.data["windGustMPH"]

@property
def precipMM(self) -> Optional[int]:
return self.data["precipMM"]

@property
def precipIN(self) -> Optional[float]:
return self.data["precipIN"]

@property
def snowCM(self) -> Optional[float]:
return self.data["snowCM"]

@property
def snowIN(self) -> Optional[float]:
return self.data["snowIN"]

@property
def visibilityKM(self) -> Optional[float]:
return self.data["visibilityKM"]

@property
def visibilityMI(self) -> Optional[float]:
return self.data["visibilityMI"]

@property
def sky(self) -> Optional[float]:
return self.data["sky"]

@property
def cloudsCoded(self) -> Optional[str]:
return self.data["cloudsCoded"]

@property
def weather(self) -> Optional[str]:
return self.data["weather"]

@property
def weatherCoded(self) -> Optional[str]:
return self.data["weatherCoded"]

@property
def weatherPrimary(self) -> Optional[str]:
return self.data["weatherPrimary"]

@property
def weatherPrimaryCoded(self) -> Optional[str]:
return self.data["weatherPrimaryCoded"]

@property
def icon(self) -> Optional[str]:
return self.data["icon"]

@property
def solradWM2(self) -> Optional[int]:
return self.data["solradWM2"]

@property
def uvi(self) -> Optional[float]:
return self.data["uvi"]

@property
def isDay(self) -> bool:
return self.data["isDay"]
Loading

0 comments on commit 0e5055d

Please sign in to comment.