From dc0b15149152f64ee9eeec3fd1870df9fee83a86 Mon Sep 17 00:00:00 2001 From: Evgeny Zinoviev Date: Sun, 8 Aug 2021 21:33:52 +0300 Subject: support json --- msshpd | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'msshpd') diff --git a/msshpd b/msshpd index cb17a96..2220fa1 100755 --- a/msshpd +++ b/msshpd @@ -7,6 +7,7 @@ from argparse import ArgumentParser routes = web.RouteTableDef() mss_host = None mss_port = None +mss_json_response = False class MySimpleSocketClient: @@ -41,7 +42,11 @@ async def variable_handler(request): client.write(command) try: - response = {'data': client.read()} + raw = client.read() + if mss_json_response: + response = json.loads(raw) + else: + response = {'data': raw} except Exception as e: response = {'error': str(e)} @@ -52,12 +57,14 @@ if __name__ == '__main__': parser = ArgumentParser() parser.add_argument('--mss-host', required=True, type=str) parser.add_argument('--mss-port', required=True, type=int) + parser.add_argument('--mss-json-response', action='store_true') parser.add_argument('--host', default='0.0.0.0', type=str) parser.add_argument('--port', default=8080, type=int) args = parser.parse_args() mss_host = args.mss_host mss_port = args.mss_port + mss_json_response = args.mss_json_response logging.basicConfig(format='%(asctime)s - %(name)s - %(levelname)s - %(message)s', level=logging.INFO) -- cgit v1.2.3