-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapi.py
More file actions
41 lines (33 loc) · 1.39 KB
/
api.py
File metadata and controls
41 lines (33 loc) · 1.39 KB
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
29
30
31
32
33
34
35
36
37
38
39
40
41
"""Module for connection to UserSide"""
from requests import get
from urllib3 import disable_warnings
from urllib3.exceptions import InsecureRequestWarning
from config import API_URL as api
disable_warnings(InsecureRequestWarning)
def api_call(cat: str, action: str, data: str = '', timeout=15) -> dict:
"""Base UserSide API call
Args:
cat (str): category
action (str): action
data (str, optional): query parameters separated with &. Defaults to ''.
Returns:
dict: API result
TODO: provide data using query params instead of one string
"""
return get(f'{api}{cat}&action={action}&{data}', verify=False, timeout=timeout).json()
# experimental query params
# def api_call(cat: str, action: str, timeout=15, **params: dict[str, str | int | float]) -> dict:
# """Base UserSide API call
# Args:
# cat (str): category
# action (str): action
# **params: query parameters.
# Returns:
# dict: API result
# """
# api_params = '&'.join([f'{key}={value}' for key, value in zip(params.keys(), params.values())])
# return get(f'{api}{cat}&action={action}&{api_params}', verify=False, timeout=timeout).json()
def set_additional_data(category, field, id , value):
"""Set additional data value"""
api_call('additional_data', 'change_value', f'cat_id={category}&field_id={field}&object_id=\
{id}&value={value}')