From 8a5346c6b0419b21baee2725df36a41f18d0aa0f Mon Sep 17 00:00:00 2001 From: Aleksey Filippov Date: Fri, 14 Jan 2022 17:43:27 +0400 Subject: [PATCH] Add code for getting parse tree from server --- syntax.py | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/syntax.py b/syntax.py index 8d5876b..1b8dda1 100644 --- a/syntax.py +++ b/syntax.py @@ -1,4 +1,23 @@ +import requests + + class Syntax: + @staticmethod + def __parsey(text, server): + print(f'Connecting to \'{server}\'...') + response = requests.post(url=f'{server}/v1/parsey-universal-full', + data=text.encode('utf-8'), + headers={ + 'Content-Type': 'text/plain; charset=utf-8', + 'Accept': 'text/plain', + 'Content-Language': 'ru' + }) + result = response.text + if response.status_code != requests.codes.ok: + response.raise_for_status() + + return result + def run(self, text: str, server: str) -> str: - return text + return self.__parsey(text, server)