diff options
author | CoprDistGit <infra@openeuler.org> | 2023-05-05 11:57:53 +0000 |
---|---|---|
committer | CoprDistGit <infra@openeuler.org> | 2023-05-05 11:57:53 +0000 |
commit | 2674ea82ed17160aa61f97c06379c62dcb88dba4 (patch) | |
tree | 47f82713bc1d6fbde952fb9464276e234dd1e1d9 | |
parent | a141802dc5de21d38e764b689ccac0bcf1db2d11 (diff) |
automatic import of python-aiowatttimeopeneuler20.03
-rw-r--r-- | .gitignore | 1 | ||||
-rw-r--r-- | python-aiowatttime.spec | 787 | ||||
-rw-r--r-- | sources | 1 |
3 files changed, 789 insertions, 0 deletions
@@ -0,0 +1 @@ +/aiowatttime-2022.10.0.tar.gz diff --git a/python-aiowatttime.spec b/python-aiowatttime.spec new file mode 100644 index 0000000..30ad1a9 --- /dev/null +++ b/python-aiowatttime.spec @@ -0,0 +1,787 @@ +%global _empty_manifest_terminate_build 0 +Name: python-aiowatttime +Version: 2022.10.0 +Release: 1 +Summary: An asyncio-based Python3 library for interacting with WattTime +License: MIT +URL: https://github.com/bachya/aiowatttime +Source0: https://mirrors.nju.edu.cn/pypi/web/packages/36/1c/13d432539e2e5cc7dfc3bbd3527b8c3458e96f7cfb261e9b61619e5c201d/aiowatttime-2022.10.0.tar.gz +BuildArch: noarch + +Requires: python3-aiohttp + +%description +# 🌎 aiowatttime: an asyncio-based, Python3 library for WattTime emissions data + +[](https://github.com/bachya/aiowatttime/actions) +[](https://pypi.python.org/pypi/aiowatttime) +[](https://pypi.python.org/pypi/aiowatttime) +[](https://github.com/bachya/aiowatttime/blob/main/LICENSE) +[](https://codecov.io/gh/bachya/aiowatttime) +[](https://codeclimate.com/github/bachya/aiowatttime/maintainability) +[](https://saythanks.io/to/bachya) + +<a href="https://www.buymeacoffee.com/bachya1208P" target="_blank"><img src="https://cdn.buymeacoffee.com/buttons/default-orange.png" alt="Buy Me A Coffee" height="41" width="174"></a> + +`aiowatttime` is a Python 3, asyncio-friendly library for interacting with +[WattTime](https://www.watttime.org) emissions data. + +- [Python Versions](#python-versions) +- [Installation](#installation) +- [Usage](#usage) +- [Contributing](#contributing) + +# Python Versions + +`aiowatttime` is currently supported on: + +- Python 3.9 +- Python 3.10 +- Python 3.11 + +# Installation + +```bash +pip install aiowatttime +``` + +# Usage + +## Getting an API Key + +Simply clone this repo and run the included interactive script: + +```bash +$ script/register +``` + +Note that WattTime offers three plans: Visitors, Analyst, and Pro. The type you use +will determine which elements of this library are available to use. You can read more +details here: https://www.watttime.org/get-the-data/data-plans/ + +## Creating and Using a Client + +The `Client` is the primary method of interacting with the API: + +```python +import asyncio + +from aiowatttime import Client + + +async def main() -> None: + client = await Client.login("<USERNAME>", "<PASSWORD>") + # ... + + +asyncio.run(main()) +``` + +By default, the library creates a new connection to the API with each coroutine. If +you are calling a large number of coroutines (or merely want to squeeze out every second of runtime savings possible), an +[`aiohttp`](https://github.com/aio-libs/aiohttp) `ClientSession` can be used for connection +pooling: + +```python +import asyncio + +from aiohttp import ClientSession + +from aiowatttime import Client + + +async def main() -> None: + async with ClientSession() as session: + client = await Client.login("<USERNAME>", "<PASSWORD>", session=session) + # ... + + +asyncio.run(main()) +``` + +## Programmatically Requesting a Password Reset + +```python +await client.async_request_password_reset() +``` + +## Getting Emissions Data + +### Grid Region + +It may be useful to first get the "grid region" (i.e., geographical info) for the area +you care about: + +```python +await client.emissions.async_get_grid_region("<LATITUDE>", "<LONGITUDE>") +# >>> { "id": 263, "abbrev": "PJM_NJ", "name": "PJM New Jersey" } +``` + +Getting emissions data will require either your latitude/longitude _or_ the "balancing +authority abbreviation" (`PJM_NJ` in the example above). + +### Realtime Data + +```python +await client.emissions.async_get_realtime_emissions("<LATITUDE>", "<LONGITUDE>") +# >>> { "freq": "300", "ba": "CAISO_NORTH", "percent": "53", "moer": "850.743982", ... } +``` + +### Forecasted Data + +```python +await client.emissions.async_get_forecasted_emissions("<BA_ABBREVATION>") +# >>> [ { "generated_at": "2021-08-05T09:05:00+00:00", "forecast": [...] } ] +``` + +You can also get the forecasted data using a specific start and end `datetime.datetime`: + +```python +from datetime import datetime + +await client.emissions.async_get_forecasted_emissions( + "<BA_ABBREVATION>", + start_datetime=datetime(2021, 1, 1), + end_datetime=datetime(2021, 2, 1), +) +# >>> [ { "generated_at": "2021-08-05T09:05:00+00:00", "forecast": [...] } ] +``` + +### Historical Data + +```python +await client.emissions.async_get_historical_emissions("<LATITUDE>", "<LONGITUDE>") +# >>> [ { "point_time": "2019-02-21T00:15:00.000Z", "value": 844, ... } ] +``` + +You can also get the historical data using a specific start and end `datetime.datetime`: + +```python +from datetime import datetime + +await client.emissions.async_get_historical_emissions( + "<LATITUDE>", + "<LONGITUDE>", + start_datetime=datetime(2021, 1, 1), + end_datetime=datetime(2021, 2, 1), +) +# >>> [ { "point_time": "2019-02-21T00:15:00.000Z", "value": 844, ... } ] +``` + +## Retry Logic + +By default, `aiowatttime` will handle expired access tokens for you. When a token expires, +the library will attempt the following sequence 3 times: + +- Request a new token +- Pause for 1 second (to be respectful of the API rate limiting) +- Execute the original request again + +Both the number of retries and the delay between retries can be configured when +instantiating a client: + +```python +import asyncio + +from aiohttp import ClientSession + +from aiowatttime import Client + + +async def main() -> None: + async with ClientSession() as session: + client = await Client.async_login( + "user", + "password", + session=session, + # Make 7 retry attempts: + request_retries=7, + # Delay 4 seconds between attempts: + request_retry_delay=4, + ) + + +asyncio.run(main()) +``` + +As always, an invalid username/password combination will immediately throw an exception. + +## Custom Logger + +By default, `aiowatttime` provides its own logger. If you should wish to use your own, you +can pass it to the client during instantiation: + +```python +import asyncio +import logging + +from aiohttp import ClientSession + +from aiowatttime import Client + +CUSTOM_LOGGER = logging.getLogger("my_custom_logger") + + +async def main() -> None: + async with ClientSession() as session: + client = await Client.async_login( + "user", + "password", + session=session, + logger=logger, + ) + + +asyncio.run(main()) +``` + +# Contributing + +1. [Check for open features/bugs](https://github.com/bachya/aiowatttime/issues) + or [initiate a discussion on one](https://github.com/bachya/aiowatttime/issues/new). +2. [Fork the repository](https://github.com/bachya/aiowatttime/fork). +3. (_optional, but highly recommended_) Create a virtual environment: `python3 -m venv .venv` +4. (_optional, but highly recommended_) Enter the virtual environment: `source ./venv/bin/activate` +5. Install the dev environment: `script/setup` +6. Code your new feature or bug fix. +7. Write tests that cover your new functionality. +8. Run tests and ensure 100% code coverage: `poetry run pytest --cov aiowatttime tests` +9. Update `README.md` with any new documentation. +10. Add yourself to `AUTHORS.md`. +11. Submit a pull request! + + +%package -n python3-aiowatttime +Summary: An asyncio-based Python3 library for interacting with WattTime +Provides: python-aiowatttime +BuildRequires: python3-devel +BuildRequires: python3-setuptools +BuildRequires: python3-pip +%description -n python3-aiowatttime +# 🌎 aiowatttime: an asyncio-based, Python3 library for WattTime emissions data + +[](https://github.com/bachya/aiowatttime/actions) +[](https://pypi.python.org/pypi/aiowatttime) +[](https://pypi.python.org/pypi/aiowatttime) +[](https://github.com/bachya/aiowatttime/blob/main/LICENSE) +[](https://codecov.io/gh/bachya/aiowatttime) +[](https://codeclimate.com/github/bachya/aiowatttime/maintainability) +[](https://saythanks.io/to/bachya) + +<a href="https://www.buymeacoffee.com/bachya1208P" target="_blank"><img src="https://cdn.buymeacoffee.com/buttons/default-orange.png" alt="Buy Me A Coffee" height="41" width="174"></a> + +`aiowatttime` is a Python 3, asyncio-friendly library for interacting with +[WattTime](https://www.watttime.org) emissions data. + +- [Python Versions](#python-versions) +- [Installation](#installation) +- [Usage](#usage) +- [Contributing](#contributing) + +# Python Versions + +`aiowatttime` is currently supported on: + +- Python 3.9 +- Python 3.10 +- Python 3.11 + +# Installation + +```bash +pip install aiowatttime +``` + +# Usage + +## Getting an API Key + +Simply clone this repo and run the included interactive script: + +```bash +$ script/register +``` + +Note that WattTime offers three plans: Visitors, Analyst, and Pro. The type you use +will determine which elements of this library are available to use. You can read more +details here: https://www.watttime.org/get-the-data/data-plans/ + +## Creating and Using a Client + +The `Client` is the primary method of interacting with the API: + +```python +import asyncio + +from aiowatttime import Client + + +async def main() -> None: + client = await Client.login("<USERNAME>", "<PASSWORD>") + # ... + + +asyncio.run(main()) +``` + +By default, the library creates a new connection to the API with each coroutine. If +you are calling a large number of coroutines (or merely want to squeeze out every second of runtime savings possible), an +[`aiohttp`](https://github.com/aio-libs/aiohttp) `ClientSession` can be used for connection +pooling: + +```python +import asyncio + +from aiohttp import ClientSession + +from aiowatttime import Client + + +async def main() -> None: + async with ClientSession() as session: + client = await Client.login("<USERNAME>", "<PASSWORD>", session=session) + # ... + + +asyncio.run(main()) +``` + +## Programmatically Requesting a Password Reset + +```python +await client.async_request_password_reset() +``` + +## Getting Emissions Data + +### Grid Region + +It may be useful to first get the "grid region" (i.e., geographical info) for the area +you care about: + +```python +await client.emissions.async_get_grid_region("<LATITUDE>", "<LONGITUDE>") +# >>> { "id": 263, "abbrev": "PJM_NJ", "name": "PJM New Jersey" } +``` + +Getting emissions data will require either your latitude/longitude _or_ the "balancing +authority abbreviation" (`PJM_NJ` in the example above). + +### Realtime Data + +```python +await client.emissions.async_get_realtime_emissions("<LATITUDE>", "<LONGITUDE>") +# >>> { "freq": "300", "ba": "CAISO_NORTH", "percent": "53", "moer": "850.743982", ... } +``` + +### Forecasted Data + +```python +await client.emissions.async_get_forecasted_emissions("<BA_ABBREVATION>") +# >>> [ { "generated_at": "2021-08-05T09:05:00+00:00", "forecast": [...] } ] +``` + +You can also get the forecasted data using a specific start and end `datetime.datetime`: + +```python +from datetime import datetime + +await client.emissions.async_get_forecasted_emissions( + "<BA_ABBREVATION>", + start_datetime=datetime(2021, 1, 1), + end_datetime=datetime(2021, 2, 1), +) +# >>> [ { "generated_at": "2021-08-05T09:05:00+00:00", "forecast": [...] } ] +``` + +### Historical Data + +```python +await client.emissions.async_get_historical_emissions("<LATITUDE>", "<LONGITUDE>") +# >>> [ { "point_time": "2019-02-21T00:15:00.000Z", "value": 844, ... } ] +``` + +You can also get the historical data using a specific start and end `datetime.datetime`: + +```python +from datetime import datetime + +await client.emissions.async_get_historical_emissions( + "<LATITUDE>", + "<LONGITUDE>", + start_datetime=datetime(2021, 1, 1), + end_datetime=datetime(2021, 2, 1), +) +# >>> [ { "point_time": "2019-02-21T00:15:00.000Z", "value": 844, ... } ] +``` + +## Retry Logic + +By default, `aiowatttime` will handle expired access tokens for you. When a token expires, +the library will attempt the following sequence 3 times: + +- Request a new token +- Pause for 1 second (to be respectful of the API rate limiting) +- Execute the original request again + +Both the number of retries and the delay between retries can be configured when +instantiating a client: + +```python +import asyncio + +from aiohttp import ClientSession + +from aiowatttime import Client + + +async def main() -> None: + async with ClientSession() as session: + client = await Client.async_login( + "user", + "password", + session=session, + # Make 7 retry attempts: + request_retries=7, + # Delay 4 seconds between attempts: + request_retry_delay=4, + ) + + +asyncio.run(main()) +``` + +As always, an invalid username/password combination will immediately throw an exception. + +## Custom Logger + +By default, `aiowatttime` provides its own logger. If you should wish to use your own, you +can pass it to the client during instantiation: + +```python +import asyncio +import logging + +from aiohttp import ClientSession + +from aiowatttime import Client + +CUSTOM_LOGGER = logging.getLogger("my_custom_logger") + + +async def main() -> None: + async with ClientSession() as session: + client = await Client.async_login( + "user", + "password", + session=session, + logger=logger, + ) + + +asyncio.run(main()) +``` + +# Contributing + +1. [Check for open features/bugs](https://github.com/bachya/aiowatttime/issues) + or [initiate a discussion on one](https://github.com/bachya/aiowatttime/issues/new). +2. [Fork the repository](https://github.com/bachya/aiowatttime/fork). +3. (_optional, but highly recommended_) Create a virtual environment: `python3 -m venv .venv` +4. (_optional, but highly recommended_) Enter the virtual environment: `source ./venv/bin/activate` +5. Install the dev environment: `script/setup` +6. Code your new feature or bug fix. +7. Write tests that cover your new functionality. +8. Run tests and ensure 100% code coverage: `poetry run pytest --cov aiowatttime tests` +9. Update `README.md` with any new documentation. +10. Add yourself to `AUTHORS.md`. +11. Submit a pull request! + + +%package help +Summary: Development documents and examples for aiowatttime +Provides: python3-aiowatttime-doc +%description help +# 🌎 aiowatttime: an asyncio-based, Python3 library for WattTime emissions data + +[](https://github.com/bachya/aiowatttime/actions) +[](https://pypi.python.org/pypi/aiowatttime) +[](https://pypi.python.org/pypi/aiowatttime) +[](https://github.com/bachya/aiowatttime/blob/main/LICENSE) +[](https://codecov.io/gh/bachya/aiowatttime) +[](https://codeclimate.com/github/bachya/aiowatttime/maintainability) +[](https://saythanks.io/to/bachya) + +<a href="https://www.buymeacoffee.com/bachya1208P" target="_blank"><img src="https://cdn.buymeacoffee.com/buttons/default-orange.png" alt="Buy Me A Coffee" height="41" width="174"></a> + +`aiowatttime` is a Python 3, asyncio-friendly library for interacting with +[WattTime](https://www.watttime.org) emissions data. + +- [Python Versions](#python-versions) +- [Installation](#installation) +- [Usage](#usage) +- [Contributing](#contributing) + +# Python Versions + +`aiowatttime` is currently supported on: + +- Python 3.9 +- Python 3.10 +- Python 3.11 + +# Installation + +```bash +pip install aiowatttime +``` + +# Usage + +## Getting an API Key + +Simply clone this repo and run the included interactive script: + +```bash +$ script/register +``` + +Note that WattTime offers three plans: Visitors, Analyst, and Pro. The type you use +will determine which elements of this library are available to use. You can read more +details here: https://www.watttime.org/get-the-data/data-plans/ + +## Creating and Using a Client + +The `Client` is the primary method of interacting with the API: + +```python +import asyncio + +from aiowatttime import Client + + +async def main() -> None: + client = await Client.login("<USERNAME>", "<PASSWORD>") + # ... + + +asyncio.run(main()) +``` + +By default, the library creates a new connection to the API with each coroutine. If +you are calling a large number of coroutines (or merely want to squeeze out every second of runtime savings possible), an +[`aiohttp`](https://github.com/aio-libs/aiohttp) `ClientSession` can be used for connection +pooling: + +```python +import asyncio + +from aiohttp import ClientSession + +from aiowatttime import Client + + +async def main() -> None: + async with ClientSession() as session: + client = await Client.login("<USERNAME>", "<PASSWORD>", session=session) + # ... + + +asyncio.run(main()) +``` + +## Programmatically Requesting a Password Reset + +```python +await client.async_request_password_reset() +``` + +## Getting Emissions Data + +### Grid Region + +It may be useful to first get the "grid region" (i.e., geographical info) for the area +you care about: + +```python +await client.emissions.async_get_grid_region("<LATITUDE>", "<LONGITUDE>") +# >>> { "id": 263, "abbrev": "PJM_NJ", "name": "PJM New Jersey" } +``` + +Getting emissions data will require either your latitude/longitude _or_ the "balancing +authority abbreviation" (`PJM_NJ` in the example above). + +### Realtime Data + +```python +await client.emissions.async_get_realtime_emissions("<LATITUDE>", "<LONGITUDE>") +# >>> { "freq": "300", "ba": "CAISO_NORTH", "percent": "53", "moer": "850.743982", ... } +``` + +### Forecasted Data + +```python +await client.emissions.async_get_forecasted_emissions("<BA_ABBREVATION>") +# >>> [ { "generated_at": "2021-08-05T09:05:00+00:00", "forecast": [...] } ] +``` + +You can also get the forecasted data using a specific start and end `datetime.datetime`: + +```python +from datetime import datetime + +await client.emissions.async_get_forecasted_emissions( + "<BA_ABBREVATION>", + start_datetime=datetime(2021, 1, 1), + end_datetime=datetime(2021, 2, 1), +) +# >>> [ { "generated_at": "2021-08-05T09:05:00+00:00", "forecast": [...] } ] +``` + +### Historical Data + +```python +await client.emissions.async_get_historical_emissions("<LATITUDE>", "<LONGITUDE>") +# >>> [ { "point_time": "2019-02-21T00:15:00.000Z", "value": 844, ... } ] +``` + +You can also get the historical data using a specific start and end `datetime.datetime`: + +```python +from datetime import datetime + +await client.emissions.async_get_historical_emissions( + "<LATITUDE>", + "<LONGITUDE>", + start_datetime=datetime(2021, 1, 1), + end_datetime=datetime(2021, 2, 1), +) +# >>> [ { "point_time": "2019-02-21T00:15:00.000Z", "value": 844, ... } ] +``` + +## Retry Logic + +By default, `aiowatttime` will handle expired access tokens for you. When a token expires, +the library will attempt the following sequence 3 times: + +- Request a new token +- Pause for 1 second (to be respectful of the API rate limiting) +- Execute the original request again + +Both the number of retries and the delay between retries can be configured when +instantiating a client: + +```python +import asyncio + +from aiohttp import ClientSession + +from aiowatttime import Client + + +async def main() -> None: + async with ClientSession() as session: + client = await Client.async_login( + "user", + "password", + session=session, + # Make 7 retry attempts: + request_retries=7, + # Delay 4 seconds between attempts: + request_retry_delay=4, + ) + + +asyncio.run(main()) +``` + +As always, an invalid username/password combination will immediately throw an exception. + +## Custom Logger + +By default, `aiowatttime` provides its own logger. If you should wish to use your own, you +can pass it to the client during instantiation: + +```python +import asyncio +import logging + +from aiohttp import ClientSession + +from aiowatttime import Client + +CUSTOM_LOGGER = logging.getLogger("my_custom_logger") + + +async def main() -> None: + async with ClientSession() as session: + client = await Client.async_login( + "user", + "password", + session=session, + logger=logger, + ) + + +asyncio.run(main()) +``` + +# Contributing + +1. [Check for open features/bugs](https://github.com/bachya/aiowatttime/issues) + or [initiate a discussion on one](https://github.com/bachya/aiowatttime/issues/new). +2. [Fork the repository](https://github.com/bachya/aiowatttime/fork). +3. (_optional, but highly recommended_) Create a virtual environment: `python3 -m venv .venv` +4. (_optional, but highly recommended_) Enter the virtual environment: `source ./venv/bin/activate` +5. Install the dev environment: `script/setup` +6. Code your new feature or bug fix. +7. Write tests that cover your new functionality. +8. Run tests and ensure 100% code coverage: `poetry run pytest --cov aiowatttime tests` +9. Update `README.md` with any new documentation. +10. Add yourself to `AUTHORS.md`. +11. Submit a pull request! + + +%prep +%autosetup -n aiowatttime-2022.10.0 + +%build +%py3_build + +%install +%py3_install +install -d -m755 %{buildroot}/%{_pkgdocdir} +if [ -d doc ]; then cp -arf doc %{buildroot}/%{_pkgdocdir}; fi +if [ -d docs ]; then cp -arf docs %{buildroot}/%{_pkgdocdir}; fi +if [ -d example ]; then cp -arf example %{buildroot}/%{_pkgdocdir}; fi +if [ -d examples ]; then cp -arf examples %{buildroot}/%{_pkgdocdir}; fi +pushd %{buildroot} +if [ -d usr/lib ]; then + find usr/lib -type f -printf "/%h/%f\n" >> filelist.lst +fi +if [ -d usr/lib64 ]; then + find usr/lib64 -type f -printf "/%h/%f\n" >> filelist.lst +fi +if [ -d usr/bin ]; then + find usr/bin -type f -printf "/%h/%f\n" >> filelist.lst +fi +if [ -d usr/sbin ]; then + find usr/sbin -type f -printf "/%h/%f\n" >> filelist.lst +fi +touch doclist.lst +if [ -d usr/share/man ]; then + find usr/share/man -type f -printf "/%h/%f.gz\n" >> doclist.lst +fi +popd +mv %{buildroot}/filelist.lst . +mv %{buildroot}/doclist.lst . + +%files -n python3-aiowatttime -f filelist.lst +%dir %{python3_sitelib}/* + +%files help -f doclist.lst +%{_docdir}/* + +%changelog +* Fri May 05 2023 Python_Bot <Python_Bot@openeuler.org> - 2022.10.0-1 +- Package Spec generated @@ -0,0 +1 @@ +d2f5ef14df63df560f4b570e70ef1f97 aiowatttime-2022.10.0.tar.gz |