Projekt

Obecné

Profil

« Předchozí | Další » 

Revize 7a278c5c

Přidáno uživatelem Jakub Šilhavý před více než 2 roky(ů)

re #9305 Implemented a simple API client, added requirements.txt

Zobrazit rozdíly:

client/api_client.py
1
import json
2
import requests
3
import logging
4

  
5
from requests import HTTPError, ConnectionError
6

  
7
from config_manager import server_url, server_port, server_endpoint
8

  
9
_uri = server_url + ":" + server_port + server_endpoint
10

  
11

  
12
def send_data(payload: dict):
13
    try:
14
        logging.info(f"sending payload = {payload} to {_uri}")
15
        response = requests.post(url=_uri, data=json.dumps(payload))
16
        logging.info(f"response text: {response.text}")
17
    except ConnectionError:
18
        logging.warning(f"sending payload = {payload} to {_uri} failed")
19
    except HTTPError as error:
20
        logging.error(f"HTTP Error ({_uri}) payload = {payload}, {error}")
client/requirements.txt
1
pyusb==1.2.1
2
requests==2.25.1
3
tendo==0.2.15
client/usb_detector/event_listener.py
3 3
import getpass
4 4
from datetime import datetime
5 5

  
6
from api_client import send_data
7

  
6 8

  
7 9
def _get_metadata() -> dict:
8 10
    return {
......
16 18
    payload = _get_metadata()
17 19
    payload["device"] = device
18 20
    payload["status"] = status
19

  
20
    # TODO send the payload off to the server
21
    send_data(payload)
21 22

  
22 23

  
23 24
def usb_connected_callback(device: dict):

Také k dispozici: Unified diff