Skip to content

Commit af0c44e

Browse files
committed
🎉 Start Comwatt Client
1 parent f3e838f commit af0c44e

5 files changed

Lines changed: 54 additions & 0 deletions

File tree

comwatt/__init__.py

Whitespace-only changes.

comwatt/client.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import requests
2+
import json
3+
4+
class ComwattClient:
5+
def __init__(self):
6+
self.base_url = 'https://energy.comwatt.com/api'
7+
8+
def authenticate(self, username, password):
9+
url = f'{self.base_url}/v1/authent'
10+
headers = {
11+
'User-Agent': 'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:109.0) Gecko/20100101 Firefox/115.0',
12+
'Accept': 'application/json, text/plain, */*',
13+
'Accept-Language': 'en-US,en;q=0.5',
14+
'Content-Type': 'application/json;charset=utf-8',
15+
'Sec-Fetch-Dest': 'empty',
16+
'Sec-Fetch-Mode': 'cors',
17+
'Sec-Fetch-Site': 'same-origin'
18+
}
19+
data = {'username': username, 'password': password}
20+
21+
response = requests.post(url, headers=headers, json=data)
22+
print(json.dumps(response.json()))
23+
if response.status_code == 200:
24+
auth_token = response.json().get('token')
25+
if auth_token:
26+
27+
return auth_token
28+
else:
29+
raise Exception('Authentication failed: No token received')
30+
else:
31+
raise Exception(f'Authentication failed: {response.status_code}')

comwatt/models.py

Whitespace-only changes.

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
requests==2.31.0

setup.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
from setuptools import setup, find_packages
2+
3+
setup(
4+
name='comwatt-client',
5+
version='0.0.1'
6+
author='Matéo Greil'
7+
author_email='contact@greil.fr'
8+
description='Python Client for Comwatt API'
9+
packages=find_packages(),
10+
install_requires=[
11+
'requests',
12+
],
13+
classifiers=[
14+
'Development Status :: 2 - Pre-Alpha',
15+
'Intended Audience :: Developers',
16+
'Programming Language :: Python :: 3',
17+
'Programming Language :: Python :: 3.6',
18+
'Programming Language :: Python :: 3.7',
19+
'Programming Language :: Python :: 3.8',
20+
'Programming Language :: Python :: 3.9',
21+
],
22+
)

0 commit comments

Comments
 (0)