pyemoncms 0.0.1__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.
Potentially problematic release.
This version of pyemoncms might be problematic. Click here for more details.
- pyemoncms-0.0.1/LICENSE +19 -0
- pyemoncms-0.0.1/PKG-INFO +18 -0
- pyemoncms-0.0.1/README.md +2 -0
- pyemoncms-0.0.1/pyemoncms.egg-info/PKG-INFO +18 -0
- pyemoncms-0.0.1/pyemoncms.egg-info/SOURCES.txt +11 -0
- pyemoncms-0.0.1/pyemoncms.egg-info/dependency_links.txt +1 -0
- pyemoncms-0.0.1/pyemoncms.egg-info/requires.txt +1 -0
- pyemoncms-0.0.1/pyemoncms.egg-info/top_level.txt +1 -0
- pyemoncms-0.0.1/pyproject.toml +6 -0
- pyemoncms-0.0.1/setup.cfg +4 -0
- pyemoncms-0.0.1/setup.py +29 -0
- pyemoncms-0.0.1/src/__init__.py +2 -0
- pyemoncms-0.0.1/src/emoncms_client.py +89 -0
pyemoncms-0.0.1/LICENSE
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
Copyright (c) 2021 The Python Packaging Authority
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
4
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
5
|
+
in the Software without restriction, including without limitation the rights
|
|
6
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
7
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
8
|
+
furnished to do so, subject to the following conditions:
|
|
9
|
+
|
|
10
|
+
The above copyright notice and this permission notice shall be included in all
|
|
11
|
+
copies or substantial portions of the Software.
|
|
12
|
+
|
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
14
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
15
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
16
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
17
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
18
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
19
|
+
SOFTWARE.
|
pyemoncms-0.0.1/PKG-INFO
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: pyemoncms
|
|
3
|
+
Version: 0.0.1
|
|
4
|
+
Summary: A python library to interrogate emoncms API
|
|
5
|
+
Home-page: https://github.com/Open-Building-Management/pyemoncms
|
|
6
|
+
Author: Alexandre CUER
|
|
7
|
+
Author-email: alexandre.cuer@wanadoo.fr
|
|
8
|
+
Project-URL: Bug Tracker, https://github.com/Open-Building-Management/pyemoncms/issues
|
|
9
|
+
Classifier: Programming Language :: Python :: 3
|
|
10
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
11
|
+
Classifier: Operating System :: OS Independent
|
|
12
|
+
Requires-Python: >=3.10
|
|
13
|
+
Description-Content-Type: text/markdown
|
|
14
|
+
License-File: LICENSE
|
|
15
|
+
Requires-Dist: aiohttp
|
|
16
|
+
|
|
17
|
+
# pyemoncms
|
|
18
|
+
python library for emoncms API
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: pyemoncms
|
|
3
|
+
Version: 0.0.1
|
|
4
|
+
Summary: A python library to interrogate emoncms API
|
|
5
|
+
Home-page: https://github.com/Open-Building-Management/pyemoncms
|
|
6
|
+
Author: Alexandre CUER
|
|
7
|
+
Author-email: alexandre.cuer@wanadoo.fr
|
|
8
|
+
Project-URL: Bug Tracker, https://github.com/Open-Building-Management/pyemoncms/issues
|
|
9
|
+
Classifier: Programming Language :: Python :: 3
|
|
10
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
11
|
+
Classifier: Operating System :: OS Independent
|
|
12
|
+
Requires-Python: >=3.10
|
|
13
|
+
Description-Content-Type: text/markdown
|
|
14
|
+
License-File: LICENSE
|
|
15
|
+
Requires-Dist: aiohttp
|
|
16
|
+
|
|
17
|
+
# pyemoncms
|
|
18
|
+
python library for emoncms API
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
LICENSE
|
|
2
|
+
README.md
|
|
3
|
+
pyproject.toml
|
|
4
|
+
setup.py
|
|
5
|
+
pyemoncms.egg-info/PKG-INFO
|
|
6
|
+
pyemoncms.egg-info/SOURCES.txt
|
|
7
|
+
pyemoncms.egg-info/dependency_links.txt
|
|
8
|
+
pyemoncms.egg-info/requires.txt
|
|
9
|
+
pyemoncms.egg-info/top_level.txt
|
|
10
|
+
src/__init__.py
|
|
11
|
+
src/emoncms_client.py
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
aiohttp
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
src
|
pyemoncms-0.0.1/setup.py
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"""setup."""
|
|
2
|
+
import setuptools
|
|
3
|
+
|
|
4
|
+
with open("README.md", "r", encoding="utf-8") as fh:
|
|
5
|
+
long_description = fh.read()
|
|
6
|
+
|
|
7
|
+
setuptools.setup(
|
|
8
|
+
name="pyemoncms",
|
|
9
|
+
version="0.0.1",
|
|
10
|
+
author="Alexandre CUER",
|
|
11
|
+
author_email="alexandre.cuer@wanadoo.fr",
|
|
12
|
+
description="A python library to interrogate emoncms API",
|
|
13
|
+
long_description=long_description,
|
|
14
|
+
long_description_content_type="text/markdown",
|
|
15
|
+
url="https://github.com/Open-Building-Management/pyemoncms",
|
|
16
|
+
project_urls={
|
|
17
|
+
"Bug Tracker": "https://github.com/Open-Building-Management/pyemoncms/issues",
|
|
18
|
+
},
|
|
19
|
+
classifiers=[
|
|
20
|
+
"Programming Language :: Python :: 3",
|
|
21
|
+
"License :: OSI Approved :: MIT License",
|
|
22
|
+
"Operating System :: OS Independent",
|
|
23
|
+
],
|
|
24
|
+
packages=setuptools.find_packages(),
|
|
25
|
+
install_requires=[
|
|
26
|
+
'aiohttp'
|
|
27
|
+
],
|
|
28
|
+
python_requires=">=3.10",
|
|
29
|
+
)
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
"""Emoncms client."""
|
|
2
|
+
|
|
3
|
+
import asyncio
|
|
4
|
+
import logging
|
|
5
|
+
from typing import Any
|
|
6
|
+
|
|
7
|
+
import aiohttp
|
|
8
|
+
|
|
9
|
+
client_exceptions = (
|
|
10
|
+
aiohttp.ClientError,
|
|
11
|
+
asyncio.TimeoutError,
|
|
12
|
+
)
|
|
13
|
+
|
|
14
|
+
HTTP_STATUS = {
|
|
15
|
+
400: "invalid request",
|
|
16
|
+
401: "unauthorized access",
|
|
17
|
+
404: "Not found",
|
|
18
|
+
406: "URI not acceptable",
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
MESSAGE_KEY = "message"
|
|
22
|
+
SUCCESS_KEY = "success"
|
|
23
|
+
|
|
24
|
+
logging.basicConfig()
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
class EmoncmsClient:
|
|
28
|
+
"""Emoncms client."""
|
|
29
|
+
|
|
30
|
+
logger = logging.getLogger(__name__)
|
|
31
|
+
|
|
32
|
+
def __init__(self, url: str, api_key: str, request_timeout: int = 20) -> None:
|
|
33
|
+
"""Initialize the client."""
|
|
34
|
+
self.logger.info("Initializing Emoncms client")
|
|
35
|
+
self.api_key = api_key
|
|
36
|
+
self.url = url
|
|
37
|
+
self.request_timeout = request_timeout
|
|
38
|
+
|
|
39
|
+
async def async_request(
|
|
40
|
+
self, path: str, params: dict[str, Any] | None = None
|
|
41
|
+
) -> dict[str, Any]:
|
|
42
|
+
"""Request emoncms server."""
|
|
43
|
+
message = f"requesting emoncms on {path}"
|
|
44
|
+
self.logger.debug(message)
|
|
45
|
+
data = {SUCCESS_KEY: False, MESSAGE_KEY: None}
|
|
46
|
+
if not params:
|
|
47
|
+
params = {"apikey": self.api_key}
|
|
48
|
+
async with aiohttp.ClientSession(self.url) as session:
|
|
49
|
+
try:
|
|
50
|
+
response = await session.get(
|
|
51
|
+
path, timeout=self.request_timeout, params=params
|
|
52
|
+
)
|
|
53
|
+
except client_exceptions as e:
|
|
54
|
+
message = f"exception {e}"
|
|
55
|
+
data[MESSAGE_KEY] = message
|
|
56
|
+
self.logger.error(message)
|
|
57
|
+
return data
|
|
58
|
+
if response.status == 200:
|
|
59
|
+
data[SUCCESS_KEY] = True
|
|
60
|
+
json_response = await response.json()
|
|
61
|
+
data[MESSAGE_KEY] = json_response
|
|
62
|
+
if MESSAGE_KEY in json_response:
|
|
63
|
+
data[MESSAGE_KEY] = json_response[MESSAGE_KEY]
|
|
64
|
+
else:
|
|
65
|
+
message = f"error {response.status}"
|
|
66
|
+
if response.status in HTTP_STATUS:
|
|
67
|
+
message = f"{message} {HTTP_STATUS[response.status]}"
|
|
68
|
+
data[MESSAGE_KEY] = message
|
|
69
|
+
self.logger.error(message)
|
|
70
|
+
return data
|
|
71
|
+
|
|
72
|
+
async def async_list_feeds(self) -> list[dict[str, Any]] | None:
|
|
73
|
+
"""Request emoncms feeds list.
|
|
74
|
+
|
|
75
|
+
return a uuid per feed if available
|
|
76
|
+
"""
|
|
77
|
+
uuid_data = await self.async_request("/user/getuuid.json")
|
|
78
|
+
feed_data = await self.async_request("/feed/list.json")
|
|
79
|
+
if feed_data[SUCCESS_KEY] and uuid_data[SUCCESS_KEY]:
|
|
80
|
+
for feed in feed_data[MESSAGE_KEY]:
|
|
81
|
+
feed["uuid"] = f"{uuid_data[MESSAGE_KEY]}_{feed['id']}"
|
|
82
|
+
if feed_data[SUCCESS_KEY]:
|
|
83
|
+
return feed_data[MESSAGE_KEY]
|
|
84
|
+
return None
|
|
85
|
+
|
|
86
|
+
async def async_get_feed_fields(self, feed_id: int) -> list[str, Any]:
|
|
87
|
+
"""Get all feed fields."""
|
|
88
|
+
params = {"apikey": self.api_key, "id": feed_id}
|
|
89
|
+
return await self.async_request("/feed/aget.json", params=params)
|