From 36e3ae8cb24a85221d8e38d0bbf1f6026f4e6830 Mon Sep 17 00:00:00 2001 From: Tobias Westphal <tj-west@gmx.de> Date: Fri, 2 Jun 2023 10:22:25 +0200 Subject: [PATCH] =?UTF-8?q?Update=20jsonparse.py:=20Dynamischer=20Pfad=20z?= =?UTF-8?q?um=20JSON-Model.=C2=A0Die=20als=20Argument=20=C3=BCbergebene=20?= =?UTF-8?q?JSON-File=20muss=20sich=20aktuell=20im=20gleichen=20Folder=20be?= =?UTF-8?q?finden.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- jsonparse.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/jsonparse.py b/jsonparse.py index 827c175..646af27 100644 --- a/jsonparse.py +++ b/jsonparse.py @@ -1,4 +1,6 @@ import json +import os +import sys from collections import namedtuple @@ -82,7 +84,15 @@ def changerange(string): print(string) -with open("soil-dummies/src/robot/model.json") as file: +try: + JSON_MODEL = sys.argv[1][:-5] + if not os.path.exists(os.path.join('..', 'SOIL OPC-UA', f'{JSON_MODEL}.json')): + raise Exception() +except Exception as e: + print('You must provide a file from the folder to be used as root file of the parsing, e.g., "python jsonparser.py model.json".') + exit() + +with open(f'{JSON_MODEL}.json') as file: #robot = json.dumps(file.read()) robotload = json.loads(file.read()) -- GitLab