forked from biemster/FindMy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
api.py
34 lines (26 loc) · 751 Bytes
/
api.py
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
"""
API
"""
from requests import Session
from helpers import status_code_success
requestSession = Session()
def handle_response(response):
"""Handle response error"""
if not status_code_success(response.status_code):
print(response.status_code, response.reason)
def fetch_devices(url, headers=None):
"""Returns id and private key for devices"""
response = requestSession.get(url, headers=headers, timeout=60)
handle_response(response)
return response.json()
def send_reports(url, data, headers=None):
"""Send reports to API"""
if not url:
return
response = requestSession.post(
url,
headers=headers,
json=data,
timeout=60,
)
handle_response(response)