Add more logging and exception

This commit is contained in:
Konstantin Lampalzer 2021-01-21 16:43:01 +00:00
parent cb10bb3a4d
commit ce1c82a192
8 changed files with 56 additions and 19 deletions

View file

@ -2,6 +2,8 @@ import requests
import json
import os
from compLib.LogstashLogging import Logging
API_URL = os.getenv("API_URL", "http://localhost:5000/") + "api/"
API_URL_GET_POS = API_URL + "getPos"
API_URL_GET_OP = API_URL + "getOp"
@ -23,7 +25,9 @@ class Seeding:
:return: An int between 0 and 3
:rtype: int
"""
return json.loads(requests.get(API_URL_GET_PARK).content)["id"]
result = json.loads(requests.get(API_URL_GET_PARK).content)["id"]
Logging.get_logger().debug(f"Seeding.get_park = {result}")
return result
@staticmethod
def pay_park() -> bool:
@ -32,7 +36,9 @@ class Seeding:
:return: True if successful, False if not successful
:rtype: bool
"""
return requests.get(API_URL_PAY_PARK).status_code == 200
result = requests.get(API_URL_PAY_PARK).status_code == 200
Logging.get_logger().debug(f"Seeding.pay_park = {result}")
return result
@staticmethod
def simon_says() -> int:
@ -41,7 +47,9 @@ class Seeding:
:return: An int between 0 and 3 or -1 after making this request 5 times.
:rtype: int
"""
return json.loads(requests.get(API_URL_SIMON_SAYS).content)["id"]
result = json.loads(requests.get(API_URL_SIMON_SAYS).content)["id"]
Logging.get_logger().debug(f"Seeding.simon_says = {result}")
return result
class Position:
@ -64,6 +72,7 @@ class DoubleElim:
:rtype: Position
"""
response = json.loads(requests.get(API_URL_GET_POS).content)
Logging.get_logger().debug(f"DoubleElim.get_position = {response}")
return Position(response["x"], response["y"], response["degrees"])
@staticmethod
@ -74,6 +83,7 @@ class DoubleElim:
:rtype: Position
"""
response = json.loads(requests.get(API_URL_GET_OP).content)
Logging.get_logger().debug(f"DoubleElim.get_opponent = x:{response}")
return Position(response["x"], response["y"], response["degrees"])
@staticmethod
@ -84,6 +94,7 @@ class DoubleElim:
:rtype: Position
"""
response = json.loads(requests.get(API_URL_GET_GOAL).content)
Logging.get_logger().debug(f"DoubleElim.get_goal = x:{response}")
return Position(response["x"], response["y"], -1)
@staticmethod
@ -93,4 +104,6 @@ class DoubleElim:
:return: A list will all items currently on the game field. Items are dictionaries that look like: {"id": 0}
:rtype: list
"""
return json.loads(requests.get(API_URL_GET_ITEMS).content)
result = json.loads(requests.get(API_URL_GET_ITEMS).content)
Logging.get_logger().debug(f"DoubleElim.get_items = {result}")
return result