python-weather 2.0.3__tar.gz → 2.0.5__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {python_weather-2.0.3/python_weather.egg-info → python_weather-2.0.5}/PKG-INFO +18 -12
- {python_weather-2.0.3 → python_weather-2.0.5}/README.md +12 -6
- {python_weather-2.0.3 → python_weather-2.0.5}/pyproject.toml +9 -9
- python_weather-2.0.5/python_weather/__init__.py +47 -0
- python_weather-2.0.5/python_weather/base.py +149 -0
- {python_weather-2.0.3 → python_weather-2.0.5}/python_weather/client.py +47 -20
- python_weather-2.0.5/python_weather/constants.py +63 -0
- {python_weather-2.0.3 → python_weather-2.0.5}/python_weather/enums.py +55 -47
- python_weather-2.0.5/python_weather/errors.py +45 -0
- python_weather-2.0.5/python_weather/forecast.py +296 -0
- {python_weather-2.0.3 → python_weather-2.0.5/python_weather.egg-info}/PKG-INFO +18 -12
- python_weather-2.0.5/python_weather.egg-info/requires.txt +1 -0
- python_weather-2.0.3/python_weather/__init__.py +0 -23
- python_weather-2.0.3/python_weather/base.py +0 -137
- python_weather-2.0.3/python_weather/constants.py +0 -39
- python_weather-2.0.3/python_weather/errors.py +0 -4
- python_weather-2.0.3/python_weather/forecast.py +0 -315
- python_weather-2.0.3/python_weather.egg-info/requires.txt +0 -1
- {python_weather-2.0.3 → python_weather-2.0.5}/LICENSE +0 -0
- {python_weather-2.0.3 → python_weather-2.0.5}/MANIFEST.in +0 -0
- {python_weather-2.0.3 → python_weather-2.0.5}/python_weather.egg-info/SOURCES.txt +0 -0
- {python_weather-2.0.3 → python_weather-2.0.5}/python_weather.egg-info/dependency_links.txt +0 -0
- {python_weather-2.0.3 → python_weather-2.0.5}/python_weather.egg-info/top_level.txt +0 -0
- {python_weather-2.0.3 → python_weather-2.0.5}/setup.cfg +0 -0
|
@@ -1,22 +1,21 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: python-weather
|
|
3
|
-
Version: 2.0.
|
|
3
|
+
Version: 2.0.5
|
|
4
4
|
Summary: A free and asynchronous weather API wrapper made in Python, for Python.
|
|
5
5
|
Author: null8626
|
|
6
6
|
License: MIT
|
|
7
|
-
Project-URL: Donations, https://ko-fi.com/null8626
|
|
8
|
-
Project-URL: Changelog, https://python-weather.readthedocs.io/en/latest/changelog.html
|
|
9
|
-
Project-URL: Homepage, https://python-weather.readthedocs.io/en/latest/
|
|
10
7
|
Project-URL: Documentation, https://python-weather.readthedocs.io/en/latest/
|
|
11
8
|
Project-URL: Repository, https://github.com/null8626/python-weather
|
|
9
|
+
Project-URL: Changelog, https://python-weather.readthedocs.io/en/latest/changelog.html
|
|
10
|
+
Project-URL: Donate via GitHub Sponsors, https://github.com/sponsors/null8626
|
|
11
|
+
Project-URL: Donate via Ko-fi, https://ko-fi.com/null8626
|
|
12
12
|
Keywords: weather,forecast,weather-api,weather-forecast
|
|
13
13
|
Classifier: Development Status :: 5 - Production/Stable
|
|
14
|
-
Classifier: Framework :: aiohttp
|
|
15
|
-
Classifier: Framework :: AsyncIO
|
|
16
14
|
Classifier: Intended Audience :: Education
|
|
17
15
|
Classifier: Intended Audience :: Developers
|
|
18
16
|
Classifier: Intended Audience :: Information Technology
|
|
19
17
|
Classifier: Natural Language :: English
|
|
18
|
+
Classifier: Operating System :: OS Independent
|
|
20
19
|
Classifier: Topic :: Education
|
|
21
20
|
Classifier: Topic :: Internet
|
|
22
21
|
Classifier: Topic :: Scientific/Engineering
|
|
@@ -32,17 +31,20 @@ Classifier: Programming Language :: Python :: 3.9
|
|
|
32
31
|
Classifier: Programming Language :: Python :: 3.10
|
|
33
32
|
Classifier: Programming Language :: Python :: 3.11
|
|
34
33
|
Classifier: Programming Language :: Python :: 3.12
|
|
34
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
35
35
|
Requires-Python: >=3.8
|
|
36
36
|
Description-Content-Type: text/markdown
|
|
37
37
|
License-File: LICENSE
|
|
38
|
-
Requires-Dist: aiohttp
|
|
38
|
+
Requires-Dist: aiohttp>=3.10.10
|
|
39
39
|
|
|
40
|
-
# [python-weather][pypi-url] [![pypi][pypi-image]][pypi-url] [![downloads][downloads-image]][pypi-url] [![ko-fi][ko-fi-brief-image]][ko-fi-url]
|
|
40
|
+
# [python-weather][pypi-url] [![pypi][pypi-image]][pypi-url] [![downloads][downloads-image]][pypi-url] [![codacy-badge][codacy-url]][codacy-image] [![ko-fi][ko-fi-brief-image]][ko-fi-url]
|
|
41
41
|
|
|
42
42
|
[pypi-image]: https://img.shields.io/pypi/v/python-weather.svg?style=flat-square
|
|
43
43
|
[pypi-url]: https://pypi.org/project/python-weather/
|
|
44
44
|
[downloads-image]: https://img.shields.io/pypi/dm/python-weather?style=flat-square
|
|
45
45
|
[ko-fi-brief-image]: https://img.shields.io/badge/donations-ko--fi-red?color=ff5e5b&style=flat-square
|
|
46
|
+
[codacy-url]: https://app.codacy.com/project/badge/Grade/0f7721b7e4314a748c75a04f0a7e0ce3
|
|
47
|
+
[codacy-image]: https://app.codacy.com/gh/null8626/python-weather/dashboard
|
|
46
48
|
[ko-fi-image]: https://ko-fi.com/img/githubbutton_sm.svg
|
|
47
49
|
[ko-fi-url]: https://ko-fi.com/null8626
|
|
48
50
|
|
|
@@ -51,7 +53,7 @@ A free and asynchronous weather Python API wrapper made in Python, for Python.
|
|
|
51
53
|
## Installation
|
|
52
54
|
|
|
53
55
|
```console
|
|
54
|
-
|
|
56
|
+
pip install python-weather
|
|
55
57
|
```
|
|
56
58
|
|
|
57
59
|
## Example
|
|
@@ -65,7 +67,7 @@ import python_weather
|
|
|
65
67
|
import asyncio
|
|
66
68
|
import os
|
|
67
69
|
|
|
68
|
-
async def getweather():
|
|
70
|
+
async def getweather() -> None:
|
|
69
71
|
# declare the client. the measuring unit used defaults to the metric system (celcius, km/h, etc.)
|
|
70
72
|
async with python_weather.Client(unit=python_weather.IMPERIAL) as client:
|
|
71
73
|
# fetch a weather forecast from a city
|
|
@@ -75,11 +77,11 @@ async def getweather():
|
|
|
75
77
|
print(weather.temperature)
|
|
76
78
|
|
|
77
79
|
# get the weather forecast for a few days
|
|
78
|
-
for daily in weather
|
|
80
|
+
for daily in weather:
|
|
79
81
|
print(daily)
|
|
80
82
|
|
|
81
83
|
# hourly forecasts
|
|
82
|
-
for hourly in daily
|
|
84
|
+
for hourly in daily:
|
|
83
85
|
print(f' --> {hourly!r}')
|
|
84
86
|
|
|
85
87
|
if __name__ == '__main__':
|
|
@@ -91,6 +93,10 @@ if __name__ == '__main__':
|
|
|
91
93
|
asyncio.run(getweather())
|
|
92
94
|
```
|
|
93
95
|
|
|
96
|
+
## Data source
|
|
97
|
+
|
|
98
|
+
This library depends on [`wttr.in`](https://github.com/chubin/wttr.in), which uses data from the [World Weather Online API](https://www.worldweatheronline.com/weather-api/).
|
|
99
|
+
|
|
94
100
|
## Donations
|
|
95
101
|
|
|
96
102
|
If you want to support this project, consider donating! ❤
|
|
@@ -1,9 +1,11 @@
|
|
|
1
|
-
# [python-weather][pypi-url] [![pypi][pypi-image]][pypi-url] [![downloads][downloads-image]][pypi-url] [![ko-fi][ko-fi-brief-image]][ko-fi-url]
|
|
1
|
+
# [python-weather][pypi-url] [![pypi][pypi-image]][pypi-url] [![downloads][downloads-image]][pypi-url] [![codacy-badge][codacy-url]][codacy-image] [![ko-fi][ko-fi-brief-image]][ko-fi-url]
|
|
2
2
|
|
|
3
3
|
[pypi-image]: https://img.shields.io/pypi/v/python-weather.svg?style=flat-square
|
|
4
4
|
[pypi-url]: https://pypi.org/project/python-weather/
|
|
5
5
|
[downloads-image]: https://img.shields.io/pypi/dm/python-weather?style=flat-square
|
|
6
6
|
[ko-fi-brief-image]: https://img.shields.io/badge/donations-ko--fi-red?color=ff5e5b&style=flat-square
|
|
7
|
+
[codacy-url]: https://app.codacy.com/project/badge/Grade/0f7721b7e4314a748c75a04f0a7e0ce3
|
|
8
|
+
[codacy-image]: https://app.codacy.com/gh/null8626/python-weather/dashboard
|
|
7
9
|
[ko-fi-image]: https://ko-fi.com/img/githubbutton_sm.svg
|
|
8
10
|
[ko-fi-url]: https://ko-fi.com/null8626
|
|
9
11
|
|
|
@@ -12,7 +14,7 @@ A free and asynchronous weather Python API wrapper made in Python, for Python.
|
|
|
12
14
|
## Installation
|
|
13
15
|
|
|
14
16
|
```console
|
|
15
|
-
|
|
17
|
+
pip install python-weather
|
|
16
18
|
```
|
|
17
19
|
|
|
18
20
|
## Example
|
|
@@ -26,7 +28,7 @@ import python_weather
|
|
|
26
28
|
import asyncio
|
|
27
29
|
import os
|
|
28
30
|
|
|
29
|
-
async def getweather():
|
|
31
|
+
async def getweather() -> None:
|
|
30
32
|
# declare the client. the measuring unit used defaults to the metric system (celcius, km/h, etc.)
|
|
31
33
|
async with python_weather.Client(unit=python_weather.IMPERIAL) as client:
|
|
32
34
|
# fetch a weather forecast from a city
|
|
@@ -36,11 +38,11 @@ async def getweather():
|
|
|
36
38
|
print(weather.temperature)
|
|
37
39
|
|
|
38
40
|
# get the weather forecast for a few days
|
|
39
|
-
for daily in weather
|
|
41
|
+
for daily in weather:
|
|
40
42
|
print(daily)
|
|
41
43
|
|
|
42
44
|
# hourly forecasts
|
|
43
|
-
for hourly in daily
|
|
45
|
+
for hourly in daily:
|
|
44
46
|
print(f' --> {hourly!r}')
|
|
45
47
|
|
|
46
48
|
if __name__ == '__main__':
|
|
@@ -52,8 +54,12 @@ if __name__ == '__main__':
|
|
|
52
54
|
asyncio.run(getweather())
|
|
53
55
|
```
|
|
54
56
|
|
|
57
|
+
## Data source
|
|
58
|
+
|
|
59
|
+
This library depends on [`wttr.in`](https://github.com/chubin/wttr.in), which uses data from the [World Weather Online API](https://www.worldweatheronline.com/weather-api/).
|
|
60
|
+
|
|
55
61
|
## Donations
|
|
56
62
|
|
|
57
63
|
If you want to support this project, consider donating! ❤
|
|
58
64
|
|
|
59
|
-
[![ko-fi][ko-fi-image]][ko-fi-url]
|
|
65
|
+
[![ko-fi][ko-fi-image]][ko-fi-url]
|
|
@@ -3,21 +3,20 @@ requires = ["setuptools"]
|
|
|
3
3
|
|
|
4
4
|
[project]
|
|
5
5
|
name = "python-weather"
|
|
6
|
-
version = "2.0.
|
|
6
|
+
version = "2.0.5"
|
|
7
7
|
description = "A free and asynchronous weather API wrapper made in Python, for Python."
|
|
8
8
|
readme = "README.md"
|
|
9
9
|
license = { text = "MIT" }
|
|
10
10
|
authors = [{ name = "null8626" }]
|
|
11
11
|
keywords = ["weather", "forecast", "weather-api", "weather-forecast"]
|
|
12
|
-
dependencies = ["aiohttp
|
|
12
|
+
dependencies = ["aiohttp>=3.10.10"]
|
|
13
13
|
classifiers = [
|
|
14
14
|
"Development Status :: 5 - Production/Stable",
|
|
15
|
-
"Framework :: aiohttp",
|
|
16
|
-
"Framework :: AsyncIO",
|
|
17
15
|
"Intended Audience :: Education",
|
|
18
16
|
"Intended Audience :: Developers",
|
|
19
17
|
"Intended Audience :: Information Technology",
|
|
20
18
|
"Natural Language :: English",
|
|
19
|
+
"Operating System :: OS Independent",
|
|
21
20
|
"Topic :: Education",
|
|
22
21
|
"Topic :: Internet",
|
|
23
22
|
"Topic :: Scientific/Engineering",
|
|
@@ -32,13 +31,14 @@ classifiers = [
|
|
|
32
31
|
"Programming Language :: Python :: 3.9",
|
|
33
32
|
"Programming Language :: Python :: 3.10",
|
|
34
33
|
"Programming Language :: Python :: 3.11",
|
|
35
|
-
"Programming Language :: Python :: 3.12"
|
|
34
|
+
"Programming Language :: Python :: 3.12",
|
|
35
|
+
"Programming Language :: Python :: 3.13"
|
|
36
36
|
]
|
|
37
37
|
requires-python = ">=3.8"
|
|
38
38
|
|
|
39
39
|
[project.urls]
|
|
40
|
-
Donations = "https://ko-fi.com/null8626"
|
|
41
|
-
Changelog = "https://python-weather.readthedocs.io/en/latest/changelog.html"
|
|
42
|
-
Homepage = "https://python-weather.readthedocs.io/en/latest/"
|
|
43
40
|
Documentation = "https://python-weather.readthedocs.io/en/latest/"
|
|
44
|
-
Repository = "https://github.com/null8626/python-weather"
|
|
41
|
+
Repository = "https://github.com/null8626/python-weather"
|
|
42
|
+
Changelog = "https://python-weather.readthedocs.io/en/latest/changelog.html"
|
|
43
|
+
"Donate via GitHub Sponsors" = "https://github.com/sponsors/null8626"
|
|
44
|
+
"Donate via Ko-fi" = "https://ko-fi.com/null8626"
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"""
|
|
2
|
+
The MIT License (MIT)
|
|
3
|
+
|
|
4
|
+
Copyright (c) 2021-2024 null8626
|
|
5
|
+
|
|
6
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
8
|
+
in the Software without restriction, including without limitation the rights
|
|
9
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
11
|
+
furnished to do so, subject to the following conditions:
|
|
12
|
+
|
|
13
|
+
The above copyright notice and this permission notice shall be included in all
|
|
14
|
+
copies or substantial portions of the Software.
|
|
15
|
+
|
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
|
+
SOFTWARE.
|
|
23
|
+
"""
|
|
24
|
+
|
|
25
|
+
from .enums import HeatIndex, Kind, Locale, Phase, UltraViolet, WindDirection
|
|
26
|
+
from .constants import METRIC, IMPERIAL
|
|
27
|
+
from .errors import Error, RequestError
|
|
28
|
+
from .client import Client
|
|
29
|
+
|
|
30
|
+
__title__ = 'python-weather'
|
|
31
|
+
__author__ = 'null8626'
|
|
32
|
+
__license__ = 'MIT'
|
|
33
|
+
__copyright__ = 'Copyright (c) 2021-2024 null8626'
|
|
34
|
+
__version__ = '2.0.5'
|
|
35
|
+
__all__ = (
|
|
36
|
+
'METRIC',
|
|
37
|
+
'IMPERIAL',
|
|
38
|
+
'Client',
|
|
39
|
+
'Error',
|
|
40
|
+
'RequestError',
|
|
41
|
+
'HeatIndex',
|
|
42
|
+
'Kind',
|
|
43
|
+
'Locale',
|
|
44
|
+
'Phase',
|
|
45
|
+
'UltraViolet',
|
|
46
|
+
'WindDirection',
|
|
47
|
+
)
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
"""
|
|
2
|
+
The MIT License (MIT)
|
|
3
|
+
|
|
4
|
+
Copyright (c) 2021-2024 null8626
|
|
5
|
+
|
|
6
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
8
|
+
in the Software without restriction, including without limitation the rights
|
|
9
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
11
|
+
furnished to do so, subject to the following conditions:
|
|
12
|
+
|
|
13
|
+
The above copyright notice and this permission notice shall be included in all
|
|
14
|
+
copies or substantial portions of the Software.
|
|
15
|
+
|
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
|
+
SOFTWARE.
|
|
23
|
+
"""
|
|
24
|
+
|
|
25
|
+
from enum import auto
|
|
26
|
+
from typing import Tuple
|
|
27
|
+
|
|
28
|
+
from .errors import Error
|
|
29
|
+
from .enums import WindDirection, Kind, Locale, UltraViolet
|
|
30
|
+
from .constants import _Unit
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
class CustomizableBase:
|
|
34
|
+
__slots__: Tuple[str, ...] = ('__unit', '__locale')
|
|
35
|
+
|
|
36
|
+
def __init__(self, unit: _Unit, locale: Locale):
|
|
37
|
+
self.unit = unit
|
|
38
|
+
self.locale = locale
|
|
39
|
+
|
|
40
|
+
@property
|
|
41
|
+
def unit(self) -> auto:
|
|
42
|
+
"""The measuring unit used to display information in this object."""
|
|
43
|
+
|
|
44
|
+
return self.__unit
|
|
45
|
+
|
|
46
|
+
@unit.setter
|
|
47
|
+
def unit(self, to: _Unit) -> None:
|
|
48
|
+
"""
|
|
49
|
+
Sets the default measuring unit used to display information in this object.
|
|
50
|
+
|
|
51
|
+
:param to: The new default measuring unit to be used to display information in this object. Must be either ``METRIC`` or ``IMPERIAL``.
|
|
52
|
+
:exception Error: If the ``to`` argument is not either ``METRIC`` or ``IMPERIAL``.
|
|
53
|
+
"""
|
|
54
|
+
|
|
55
|
+
if not isinstance(to, _Unit):
|
|
56
|
+
raise Error('Invalid measuring unit specified!')
|
|
57
|
+
|
|
58
|
+
self.__unit = to
|
|
59
|
+
|
|
60
|
+
@property
|
|
61
|
+
def locale(self) -> Locale:
|
|
62
|
+
"""The localization used to display information in this object."""
|
|
63
|
+
|
|
64
|
+
return self.__locale
|
|
65
|
+
|
|
66
|
+
@locale.setter
|
|
67
|
+
def locale(self, to: Locale) -> None:
|
|
68
|
+
"""
|
|
69
|
+
Sets the default localization used to display information in this object.
|
|
70
|
+
|
|
71
|
+
:param to: The new :class:`Locale` to be used to display information in this object.
|
|
72
|
+
:type to: Locale
|
|
73
|
+
:exception Error: If the ``to`` argument is not a part of the :class:`Locale` enum.
|
|
74
|
+
"""
|
|
75
|
+
|
|
76
|
+
if not isinstance(to, Locale):
|
|
77
|
+
raise Error(f'Expected {to!r} to be a Locale enum')
|
|
78
|
+
|
|
79
|
+
self.__locale = to
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
class BaseForecast:
|
|
83
|
+
__slots__: Tuple[str, ...] = (
|
|
84
|
+
'ultraviolet',
|
|
85
|
+
'humidity',
|
|
86
|
+
'wind_direction',
|
|
87
|
+
'kind',
|
|
88
|
+
'feels_like',
|
|
89
|
+
'temperature',
|
|
90
|
+
'precipitation',
|
|
91
|
+
'pressure',
|
|
92
|
+
'visibility',
|
|
93
|
+
'wind_speed',
|
|
94
|
+
'description',
|
|
95
|
+
)
|
|
96
|
+
|
|
97
|
+
ultraviolet: UltraViolet
|
|
98
|
+
"""The ultra-violet (UV) index."""
|
|
99
|
+
|
|
100
|
+
humidity: int
|
|
101
|
+
"""The humidity value in percent."""
|
|
102
|
+
|
|
103
|
+
wind_direction: WindDirection
|
|
104
|
+
"""The wind direction."""
|
|
105
|
+
|
|
106
|
+
kind: Kind
|
|
107
|
+
"""The kind of the forecast."""
|
|
108
|
+
|
|
109
|
+
feels_like: int
|
|
110
|
+
"""What it felt like, in celcius or fahrenheit."""
|
|
111
|
+
|
|
112
|
+
temperature: int
|
|
113
|
+
"""The temperature in either celcius or Fahrenheit."""
|
|
114
|
+
|
|
115
|
+
precipitation: float
|
|
116
|
+
"""The precipitation in either millimeters or inches."""
|
|
117
|
+
|
|
118
|
+
pressure: float
|
|
119
|
+
"""The pressure in either pascal or inches."""
|
|
120
|
+
|
|
121
|
+
visibility: int
|
|
122
|
+
"""The visibility distance in either kilometers or miles."""
|
|
123
|
+
|
|
124
|
+
wind_speed: int
|
|
125
|
+
"""The wind speeds in either kilometers/hour or miles/hour."""
|
|
126
|
+
|
|
127
|
+
description: str
|
|
128
|
+
"""The description regarding the forecast. This can be localized in different languages depending on the localization used."""
|
|
129
|
+
|
|
130
|
+
def __init__(self, json: dict, unit: _Unit, locale: Locale):
|
|
131
|
+
description = (
|
|
132
|
+
json['weatherDesc'][0]['value']
|
|
133
|
+
if locale is Locale.ENGLISH
|
|
134
|
+
else json[f'lang_{locale.value}'][0]['value']
|
|
135
|
+
)
|
|
136
|
+
|
|
137
|
+
self.ultraviolet = UltraViolet._new(int(json['uvIndex']))
|
|
138
|
+
self.humidity = int(json['humidity'])
|
|
139
|
+
self.wind_direction = WindDirection._new(
|
|
140
|
+
json['winddir16Point'], int(json['winddirDegree'])
|
|
141
|
+
)
|
|
142
|
+
self.kind = Kind(int(json['weatherCode']))
|
|
143
|
+
self.feels_like = int(json[f'FeelsLike{unit.temperature}'])
|
|
144
|
+
self.temperature = int(json[f'temp_{unit.temperature}'])
|
|
145
|
+
self.precipitation = float(json[f'precip{unit.precipitation}'])
|
|
146
|
+
self.pressure = float(json[f'pressure{unit.pressure}'])
|
|
147
|
+
self.visibility = int(json[f'visibility{unit.visibility}'])
|
|
148
|
+
self.wind_speed = int(json[f'windspeed{unit.velocity}'])
|
|
149
|
+
self.description = description.strip()
|
|
@@ -1,13 +1,37 @@
|
|
|
1
|
+
"""
|
|
2
|
+
The MIT License (MIT)
|
|
3
|
+
|
|
4
|
+
Copyright (c) 2021-2024 null8626
|
|
5
|
+
|
|
6
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
8
|
+
in the Software without restriction, including without limitation the rights
|
|
9
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
11
|
+
furnished to do so, subject to the following conditions:
|
|
12
|
+
|
|
13
|
+
The above copyright notice and this permission notice shall be included in all
|
|
14
|
+
copies or substantial portions of the Software.
|
|
15
|
+
|
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
|
+
SOFTWARE.
|
|
23
|
+
"""
|
|
24
|
+
|
|
1
25
|
from aiohttp import ClientSession, ClientTimeout, TCPConnector
|
|
2
26
|
from urllib.parse import quote_plus
|
|
3
|
-
from typing import Optional
|
|
27
|
+
from typing import Optional, Tuple
|
|
4
28
|
from asyncio import sleep
|
|
5
29
|
from enum import auto
|
|
6
30
|
|
|
31
|
+
from .errors import Error, RequestError
|
|
7
32
|
from .constants import _Unit, METRIC
|
|
8
33
|
from .base import CustomizableBase
|
|
9
34
|
from .forecast import Forecast
|
|
10
|
-
from .errors import Error
|
|
11
35
|
from .enums import Locale
|
|
12
36
|
|
|
13
37
|
|
|
@@ -22,10 +46,10 @@ class Client(CustomizableBase):
|
|
|
22
46
|
:param session: Whether to use an existing aiohttp client session for requesting or not. Defaults to ``None`` (creates a new one instead)
|
|
23
47
|
:type session: Optional[:class:`aiohttp.ClientSession`]
|
|
24
48
|
|
|
25
|
-
:raises Error: If
|
|
49
|
+
:raises Error: If ``unit`` is not ``METRIC`` or ``IMPERIAL``, or if ``locale`` is not ``None`` and not a part of the :class:`Locale` enum.
|
|
26
50
|
"""
|
|
27
51
|
|
|
28
|
-
__slots__ = ('__session'
|
|
52
|
+
__slots__: Tuple[str, ...] = ('__own_session', '__session')
|
|
29
53
|
|
|
30
54
|
def __init__(
|
|
31
55
|
self,
|
|
@@ -36,13 +60,14 @@ class Client(CustomizableBase):
|
|
|
36
60
|
):
|
|
37
61
|
super().__init__(unit, locale)
|
|
38
62
|
|
|
63
|
+
self.__own_session = session is None
|
|
39
64
|
self.__session = session or ClientSession(
|
|
40
65
|
timeout=ClientTimeout(total=5000.0),
|
|
41
66
|
connector=TCPConnector(verify_ssl=False),
|
|
42
67
|
)
|
|
43
68
|
|
|
44
69
|
def __repr__(self) -> str:
|
|
45
|
-
return f'<{
|
|
70
|
+
return f'<{__class__.__name__} {self.__session!r}>'
|
|
46
71
|
|
|
47
72
|
async def get(
|
|
48
73
|
self,
|
|
@@ -56,9 +81,9 @@ class Client(CustomizableBase):
|
|
|
56
81
|
|
|
57
82
|
:param location: The requested location name for said weather forecast.
|
|
58
83
|
:type location: str
|
|
59
|
-
:param unit: Overrides the
|
|
84
|
+
:param unit: Overrides the unit used by this object. Defaults to the one used by this object.
|
|
60
85
|
:type unit: Optional[:py:class:`enum.auto`]
|
|
61
|
-
:param locale: Overrides the locale
|
|
86
|
+
:param locale: Overrides the locale used by this object. Defaults to the one used by this object.
|
|
62
87
|
:type locale: Optional[Locale]
|
|
63
88
|
|
|
64
89
|
:exception Error: If the aiohttp client session used by the :class:`Client` object is already closed, if the ``unit`` argument is not ``None`` and it's also not ``METRIC`` or ``IMPERIAL``, if the ``locale`` argument is not ``None`` and it's also not a part of the :class:`Locale` enum, or if the :class:`Client` cannot send a web request to the web server.
|
|
@@ -82,25 +107,27 @@ class Client(CustomizableBase):
|
|
|
82
107
|
delay = 0.5
|
|
83
108
|
|
|
84
109
|
while True:
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
110
|
+
try:
|
|
111
|
+
async with self.__session.get(
|
|
112
|
+
f'https://{subdomain}wttr.in/{quote_plus(location)}?format=j1'
|
|
113
|
+
) as resp:
|
|
114
|
+
resp.raise_for_status()
|
|
115
|
+
|
|
89
116
|
return Forecast(await resp.json(), unit, locale)
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
117
|
+
except Exception as err:
|
|
118
|
+
if delay == 4:
|
|
119
|
+
raise RequestError(err)
|
|
93
120
|
|
|
94
|
-
|
|
95
|
-
|
|
121
|
+
await sleep(delay)
|
|
122
|
+
delay *= 2
|
|
96
123
|
|
|
97
|
-
async def close(self):
|
|
98
|
-
"""Closes the :class:`Client` object. Nothing will happen if
|
|
124
|
+
async def close(self) -> None:
|
|
125
|
+
"""Closes the :class:`Client` object. Nothing will happen if the client uses a pre-existing :class:`aiohttp.ClientSession` or if the session is already closed."""
|
|
99
126
|
|
|
100
|
-
if not self.__session.closed:
|
|
127
|
+
if self.__own_session and not self.__session.closed:
|
|
101
128
|
await self.__session.close()
|
|
102
129
|
|
|
103
|
-
async def __aenter__(self):
|
|
130
|
+
async def __aenter__(self) -> 'Client':
|
|
104
131
|
return self
|
|
105
132
|
|
|
106
133
|
async def __aexit__(self, *_, **__):
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
"""
|
|
2
|
+
The MIT License (MIT)
|
|
3
|
+
|
|
4
|
+
Copyright (c) 2021-2024 null8626
|
|
5
|
+
|
|
6
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
8
|
+
in the Software without restriction, including without limitation the rights
|
|
9
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
11
|
+
furnished to do so, subject to the following conditions:
|
|
12
|
+
|
|
13
|
+
The above copyright notice and this permission notice shall be included in all
|
|
14
|
+
copies or substantial portions of the Software.
|
|
15
|
+
|
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
|
+
SOFTWARE.
|
|
23
|
+
"""
|
|
24
|
+
|
|
25
|
+
from typing import Union, Tuple
|
|
26
|
+
import re
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
class _Unit:
|
|
30
|
+
__slots__: Tuple[str, ...] = (
|
|
31
|
+
'temperature',
|
|
32
|
+
'velocity',
|
|
33
|
+
'pressure',
|
|
34
|
+
'precipitation',
|
|
35
|
+
'visibility',
|
|
36
|
+
'cm_divisor',
|
|
37
|
+
)
|
|
38
|
+
|
|
39
|
+
def __init__(
|
|
40
|
+
self,
|
|
41
|
+
temperature: str,
|
|
42
|
+
velocity: str,
|
|
43
|
+
pressure: str,
|
|
44
|
+
precipitation: str,
|
|
45
|
+
visibility: str,
|
|
46
|
+
cm_divisor: Union[int, float],
|
|
47
|
+
):
|
|
48
|
+
self.temperature = temperature
|
|
49
|
+
self.velocity = velocity
|
|
50
|
+
self.pressure = pressure
|
|
51
|
+
self.precipitation = precipitation
|
|
52
|
+
self.visibility = visibility
|
|
53
|
+
self.cm_divisor = cm_divisor
|
|
54
|
+
|
|
55
|
+
def __repr__(self) -> str:
|
|
56
|
+
return f'<Unit [{self.temperature}, {self.velocity}]>'
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
METRIC = _Unit('C', 'Kmph', '', 'MM', '', 1)
|
|
60
|
+
IMPERIAL = _Unit('F', 'Miles', 'Inches', 'Inches', 'Miles', 2.54)
|
|
61
|
+
|
|
62
|
+
WIND_DIRECTION_EMOJIS = ('↓', '↙', '←', '↖', '↑', '↗', '→', '↘')
|
|
63
|
+
LATLON_REGEX = re.compile(r'^Lat (\-?[\d\.]+) and Lon (\-?[\d\.]+)$')
|