added seeding api
This commit is contained in:
parent
52c22995d3
commit
f03b9d51b5
1 changed files with 56 additions and 0 deletions
56
client_s2/compLib/Api.py
Normal file
56
client_s2/compLib/Api.py
Normal file
|
@ -0,0 +1,56 @@
|
||||||
|
import json
|
||||||
|
import logging
|
||||||
|
import os
|
||||||
|
from typing import Dict, Tuple, List
|
||||||
|
|
||||||
|
import requests
|
||||||
|
|
||||||
|
logger = logging.getLogger("seeding-api")
|
||||||
|
|
||||||
|
API_URL = os.getenv("API_URL", "http://localhost:5000/") + "api/"
|
||||||
|
|
||||||
|
api_override = os.getenv("API_FORCE", "")
|
||||||
|
|
||||||
|
if api_override != "":
|
||||||
|
print(f"API_URL was set to {API_URL} but was overwritten with {api_override}")
|
||||||
|
API_URL = api_override
|
||||||
|
|
||||||
|
API_URL_GET_HEU = API_URL + "getHeuballen"
|
||||||
|
API_URL_GET_LOGISTIC_PLAN = API_URL + "getLogisticPlan"
|
||||||
|
API_URL_GET_ROBOT_STATE = API_URL + "getRobotState"
|
||||||
|
|
||||||
|
|
||||||
|
class Seeding:
|
||||||
|
"""Class used for communicating with seeding api
|
||||||
|
"""
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def get_heu() -> Tuple[Dict, int]:
|
||||||
|
"""Makes the /api/getHeuballen call to the api.
|
||||||
|
|
||||||
|
:return: Json Object and status code as returned by the api.
|
||||||
|
:rtype: Tuple[Dict, int]
|
||||||
|
"""
|
||||||
|
res = requests.get(API_URL_GET_HEU)
|
||||||
|
result = json.loads(res.content)
|
||||||
|
logger.debug(f"Seeding.get_heu = {result}, status code = {res.status_code}")
|
||||||
|
return result
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def get_logistic_plan() -> Tuple[Dict, int]:
|
||||||
|
"""Makes the /api/getLogisticPlan call to the api.
|
||||||
|
|
||||||
|
:return: Json Object and status code as returned by the api.
|
||||||
|
:rtype: List
|
||||||
|
"""
|
||||||
|
res = requests.get(API_URL_GET_LOGISTIC_PLAN)
|
||||||
|
result = json.loads(res.content)
|
||||||
|
logger.debug(f"Seeding.get_logistic_plan = {result}, status code = {res.status_code}")
|
||||||
|
return result
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def get_robot_state() -> Tuple[Dict, int]:
|
||||||
|
res = requests.get(API_URL_GET_ROBOT_STATE)
|
||||||
|
result = json.loads(res.content)
|
||||||
|
logger.debug(f"Seeding.get_robot_state {result}, status code = {res.status_code}")
|
||||||
|
return result, res.status_code
|
Reference in a new issue