def put(put_request: PutRequest) -> Verdict: api = Api() try: unit_name = randomize() id_of_basement = api.add_new_chess_unit(put_request.hostname, unit_name, put_request.flag) armory_id = randomize() new_armory_id = api.add_armory_unit(put_request.hostname, armory_id) result = api.add_unit_to_chess(put_request.hostname, unit_name, new_armory_id) last_50_objects = api.get_latest_objects(put_request.hostname, 50) if "Armory" not in str(api.object_info(put_request.hostname, unit_name)): print("Armory not in object") return Verdict.MUMBLE("Bad object") if unit_name not in last_50_objects or result not in last_50_objects or armory_id not in last_50_objects: print("last 50 object doesnt contain needed info") return Verdict.MUMBLE("bad objects listing") if result != unit_name: print("result != unit name") return Verdict.MUMBLE("bad object id after adding") if armory_id != new_armory_id: print("bad armory id") return Verdict.MUMBLE("bad object id after adding") return Verdict.OK(f"{unit_name}:{id_of_basement}") except RequestException as e: print(f"timeout on connect {e}") return Verdict.DOWN("timeout") except Exception as e: print(f"possible mumble, {e}") return Verdict.MUMBLE("bad proto")
import sys from api import Api import re host = sys.argv[1] api = Api() latest_objects = api.get_latest_objects(host, 50) found = [] for obj_id in latest_objects: try: api.add_unit_to_chess(host, obj_id, "0") api.add_unit_to_chess(host, obj_id, obj_id) result = api.object_info(host, obj_id) lst = re.findall(r'\w{31}=', result) if lst: found += lst except: pass print(len(set(found))) print(*set(found), sep='\n')