Compare commits
2 Commits
14051edfc5
...
8fa91a9c55
Author | SHA1 | Date |
---|---|---|
Tanner Collin | 8fa91a9c55 | 2 years ago |
Tanner Collin | 055b12ee05 | 2 years ago |
3 changed files with 77 additions and 74 deletions
@ -1 +1,9 @@ |
||||
pyunifiprotect==1.1.0 |
||||
aiohttp==3.8.1 |
||||
aiosignal==1.2.0 |
||||
async-timeout==4.0.2 |
||||
attrs==21.4.0 |
||||
charset-normalizer==2.0.12 |
||||
frozenlist==1.3.0 |
||||
idna==3.3 |
||||
multidict==6.0.2 |
||||
yarl==1.7.2 |
||||
|
@ -0,0 +1,41 @@ |
||||
import asyncio |
||||
import aiohttp |
||||
import zlib |
||||
import struct |
||||
import json |
||||
|
||||
import settings |
||||
|
||||
HEADER_LENGTH = 8 |
||||
|
||||
async def connect(): |
||||
data = dict( |
||||
username=settings.UFP_USERNAME, |
||||
password=settings.UFP_PASSWORD, |
||||
rememberMe=True, |
||||
) |
||||
|
||||
async with aiohttp.ClientSession() as session: |
||||
async with session.post(settings.UFP_ADDRESS + '/api/auth/login', json=data, ssl=False) as resp: |
||||
cookie = resp.cookies['TOKEN'] |
||||
|
||||
headers = {'cookie': cookie.key + '=' + cookie.value} |
||||
async with session.ws_connect(settings.UFP_ADDRESS + '/proxy/protect/ws/updates', headers=headers, ssl=False) as ws: |
||||
async for msg in ws: |
||||
packet_type, payload_format, deflated, unknown, payload_size = struct.unpack('!bbbbi', msg.data[0:HEADER_LENGTH]) |
||||
action_start = HEADER_LENGTH |
||||
action_packet = zlib.decompress(msg.data[action_start:]) |
||||
data_start = payload_size + 2*HEADER_LENGTH |
||||
data_packet = zlib.decompress(msg.data[data_start:]) |
||||
|
||||
yield json.loads(data_packet.decode()) |
||||
|
||||
|
||||
async def test(): |
||||
async for msg in connect(): |
||||
print(msg) |
||||
|
||||
if __name__ == '__main__': |
||||
loop = asyncio.get_event_loop() |
||||
loop.run_until_complete(test()) |
||||
loop.close() |
Loading…
Reference in new issue