Skip to content

Commit

Permalink
update 0.3.4: add support for python 3.7 users
Browse files Browse the repository at this point in the history
  • Loading branch information
null8626 committed Jun 27, 2021
1 parent e49e4ca commit 7bf8cbd
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 31 deletions.
2 changes: 1 addition & 1 deletion python_weather/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,5 @@

METRIC = "C"
IMPERIAL = "F"
__version__ = "0.3.1"
__version__ = "0.3.4"
__all__ = ("Client", "METRIC", "IMPERIAL", "HTTPException", "__version__")
55 changes: 28 additions & 27 deletions python_weather/response.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ def __init__(self, response: dict):
self._get = response.get

def __getitem__(self, key: str):
if (res := self._get(key)):
res = self._get(key)
if res:
return res
raise KeyError(key)

Expand All @@ -23,14 +24,14 @@ def __repr__(self) -> str:
@property
def low(self) -> int:
""" Returns the lowest predicted temperature for the forecast. """
if (temp := self._get('@low')):
return int(temp)
temp = self._get('@low')
return int(temp) if temp else None

@property
def high(self) -> int:
""" Returns the highest predicted temperature for the forecast. """
if (temp := self._get('@high')):
return int(temp)
temp = self._get('@high')
return int(temp) if temp else None

@property
def temperature(self) -> int:
Expand All @@ -40,8 +41,8 @@ def temperature(self) -> int:
@property
def sky_code_day(self) -> int:
""" Returns the sky code day for the weather forecast. """
if (code := self._get('@skycodeday')):
return int(code)
code = self._get('@skycodeday')
return int(code) if code else None

@property
def sky_text(self) -> str:
Expand Down Expand Up @@ -69,8 +70,8 @@ def short_day(self) -> str:
@property
def precip(self) -> int:
""" Returns the precipitation value. """
if (val := self._get('@precip')):
return int(val)
val = self._get('@precip')
return int(val) if val else None

class CurrentForecast(BaseResponse):
def __init__(self, forecast_obj: dict):
Expand All @@ -82,14 +83,14 @@ def __repr__(self) -> str:
@property
def temperature(self) -> int:
""" Returns the current weather temperature. """
if (temp := self._get('@temperature')):
return int(temp)
temp = self._get('@temperature')
return int(temp) if temp else None

@property
def sky_code(self) -> int:
""" Returns the sky code for the current weather. """
if (code := self._get('@skycode')):
return int(code)
code = self._get('@skycode')
return int(code) if code else None

@property
def sky_text(self) -> str:
Expand All @@ -113,14 +114,14 @@ def observation_point(self) -> str:
@property
def feels_like(self) -> int:
""" Returns the temperature of what it feels like. """
if (temp := self._get('@feelslike')):
return int(temp)
temp = self._get('@feelslike')
return int(temp) if temp else None

@property
def humidity(self) -> int:
""" Returns the humidity level. """
if (temp := self._get('@humidity')):
return int(temp)
temp = self._get('@humidity')
return int(temp) if temp else None

@property
def wind_display(self) -> str:
Expand Down Expand Up @@ -155,8 +156,8 @@ def __repr__(self) -> str:
@property
def current(self) -> "CurrentForecast":
""" Returns the CurrentForecast object for the weather object. """
if (current := self._get('current')):
return CurrentForecast(current)
current = self._get('current')
return CurrentForecast(current) if currrent else None

@property
def forecasts(self) -> List[WeatherForecast]:
Expand Down Expand Up @@ -194,20 +195,20 @@ def provider(self) -> str:
@property
def latitude(self) -> float:
""" Returns the latitude of the weather's location. """
if (lat := self._get('@lat')):
return float(lat)
lat = self._get('@lat')
return float(lat) if lat else None

@property
def longitude(self) -> float:
""" Returns the longitude of the weather's location. """
if (long := self._get('@long')):
return float(long)
long = self._get('@long')
return float(long) if long else None

@property
def timezone_offset(self) -> int:
""" Returns the timezone offset. """
if (offset := self._get('@timezone')):
return int(offset)
offset = self._get('@timezone')
return int(offset) if offset else None

@property
def alert_message(self) -> str:
Expand All @@ -217,8 +218,8 @@ def alert_message(self) -> str:
@property
def entity_id(self) -> int:
""" Returns the entity ID for the weather forecast. """
if (id := self._get('@entityid')):
return int(id)
id = self._get('@entityid')
return int(id) if id else None

@property
def provider_attribution(self) -> str:
Expand Down
3 changes: 2 additions & 1 deletion python_weather/rest.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ async def request(self, location: str) -> dict:
self.cache[url] = await resp.text()

parsed = parse(self.cache[url])
if (error_message := parsed.get('string')):
error_message = parsed.get('string')
if error_message:
raise HTTPException(response, error_message['#text'])
elif resp.status >= 400:
raise HTTPException(response)
Expand Down
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
setup(
name='python-weather',
packages=['python_weather'],
version='0.3.3',
version='0.3.4',
license='MIT',
description='A free and asynchronous Weather API Wrapper.',
long_description=open('README.md', 'r', encoding='utf-8').read(),
long_description_content_type='text/markdown',
author='vierofernando',
author_email='[email protected]',
url='https://github.com/vierofernando/python-weather',
download_url='https://github.com/vierofernando/python-weather/archive/0.3.3.tar.gz',
download_url='https://github.com/vierofernando/python-weather/archive/0.3.4.tar.gz',
keywords=['Weather', 'API', 'Weather API', 'API Wrapper', 'Weather CLI', 'CLI'],
install_requires=[
'aiohttp>=3.7.4',
Expand Down

0 comments on commit 7bf8cbd

Please sign in to comment.