File: create_session.py

package info (click to toggle)
python-wolf-comm 0.0.47-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,204 kB
  • sloc: python: 1,008; makefile: 3
file content (28 lines) | stat: -rw-r--r-- 1,084 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
from datetime import datetime

from httpx import AsyncClient, Headers

from wolf_comm import constants
from wolf_comm.constants import SESSION_ID, TIMESTAMP
from wolf_comm.helpers import bearer_header


async def create_session(client: AsyncClient, token: str):
    data = {
        TIMESTAMP: datetime.now().strftime("%Y-%m-%d %H:%M:%S")
    }
    resp = await client.post(constants.BASE_URL_PORTAL + "/api/portal/CreateSession2",
                              headers=Headers({**bearer_header(token),
                                               **{"Content-Type": "application/json"}}),
                              json=data)

    return resp.json()['BrowserSessionId']

async def update_session(client: AsyncClient, token: str, session_id: str):
    data = {
        SESSION_ID: session_id
    }
    await client.post(constants.BASE_URL_PORTAL + "/api/portal/UpdateSession",
                              headers=Headers({**bearer_header(token),
                                               **{"Content-Type": "application/json"}}),
                              json=data)