Prepared dockerfile
This commit is contained in:
8
Backend-libXML/Dockerfile
Normal file
8
Backend-libXML/Dockerfile
Normal file
@@ -0,0 +1,8 @@
|
||||
FROM tiangolo/meinheld-gunicorn-flask:python3.9
|
||||
|
||||
COPY ./requirements.txt /app/requirements.txt
|
||||
|
||||
RUN pip install --no-cache-dir --upgrade -r /app/requirements.txt
|
||||
|
||||
COPY ./main.py /app/
|
||||
COPY ./Parser.py /app/
|
||||
@@ -1,17 +1,69 @@
|
||||
from flask import Flask
|
||||
from flask import request
|
||||
from lxml import etree
|
||||
import json
|
||||
import time
|
||||
import Parser
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
SOURCE = "sample/xslt.xml"
|
||||
XSLT = "sample/sample.xslt"
|
||||
app = Flask(__name__)
|
||||
|
||||
file = open(SOURCE, "r")
|
||||
xml = file.read()
|
||||
file.close()
|
||||
@app.route("/xpath", methods=["POST"])
|
||||
def xpath():
|
||||
request_data = request.get_json()
|
||||
xml = request_data['data']
|
||||
xpath = request_data['process']
|
||||
|
||||
file = open(XSLT, "r")
|
||||
xslt = file.read()
|
||||
print(Parser.xslt(xml, xslt))
|
||||
response = dict()
|
||||
start = time.time_ns()
|
||||
try:
|
||||
response['result'] = Parser.xpath(xml, xpath)
|
||||
response['status'] = "OK"
|
||||
except BaseException as e:
|
||||
response['result'] = str(e)
|
||||
response['status'] = "ERR"
|
||||
finally:
|
||||
exec_time = (time.time_ns() - start) / 10**6
|
||||
response['time'] = f"{exec_time:.03f}"
|
||||
response['processor'] = "libxml2 over lxml"
|
||||
return json.dumps(response)
|
||||
|
||||
file.close()
|
||||
@app.route("/xsd", methods=["POST"])
|
||||
def xsd():
|
||||
request_data = request.get_json()
|
||||
xml = request_data['data']
|
||||
xsd = request_data['process']
|
||||
|
||||
response = dict()
|
||||
start = time.time_ns()
|
||||
try:
|
||||
response['result'] = Parser.xsd(xml, xsd)
|
||||
response['status'] = "OK"
|
||||
except BaseException as e:
|
||||
response['result'] = str(e)
|
||||
response['status'] = "ERR"
|
||||
finally:
|
||||
exec_time = (time.time_ns() - start) / 10**6
|
||||
response['time'] = f"{exec_time:.03f}"
|
||||
response['processor'] = "libxml2 over lxml"
|
||||
return json.dumps(response)
|
||||
|
||||
@app.route("/xslt", methods=["POST"])
|
||||
def xslt():
|
||||
request_data = request.get_json()
|
||||
xml = request_data['data']
|
||||
xslt = request_data['process']
|
||||
|
||||
response = dict()
|
||||
start = time.time_ns()
|
||||
try:
|
||||
response['result'] = Parser.xslt(xml, xslt)
|
||||
response['status'] = "OK"
|
||||
except BaseException as e:
|
||||
response['result'] = str(e)
|
||||
response['status'] = "ERR"
|
||||
finally:
|
||||
exec_time = (time.time_ns() - start) / 10**6
|
||||
response['time'] = f"{exec_time:.03f}"
|
||||
response['processor'] = "libxml2 over lxml"
|
||||
return json.dumps(response)
|
||||
2
Backend-libXML/requirements.txt
Normal file
2
Backend-libXML/requirements.txt
Normal file
@@ -0,0 +1,2 @@
|
||||
lxml
|
||||
flask
|
||||
@@ -1,4 +1,4 @@
|
||||
url = "http://localhost:5000/xsd"
|
||||
url = "http://localhost:8082/xsd"
|
||||
data = "@xsd.json"
|
||||
header = "Content-Type: application/json"
|
||||
request = POST
|
||||
|
||||
@@ -1,69 +0,0 @@
|
||||
from flask import Flask
|
||||
from flask import request
|
||||
from lxml import etree
|
||||
import json
|
||||
import time
|
||||
import Parser
|
||||
|
||||
|
||||
app = Flask(__name__)
|
||||
|
||||
@app.route("/xpath", methods=["POST"])
|
||||
def xpath():
|
||||
request_data = request.get_json()
|
||||
xml = request_data['data']
|
||||
xpath = request_data['process']
|
||||
|
||||
response = dict()
|
||||
start = time.time_ns()
|
||||
try:
|
||||
response['result'] = Parser.xpath(xml, xpath)
|
||||
response['status'] = "OK"
|
||||
except BaseException as e:
|
||||
response['result'] = str(e)
|
||||
response['status'] = "ERR"
|
||||
finally:
|
||||
exec_time = (time.time_ns() - start) / 10**6
|
||||
response['time'] = f"{exec_time:.03f}"
|
||||
response['processor'] = "libxml2 over lxml"
|
||||
return json.dumps(response)
|
||||
|
||||
@app.route("/xsd", methods=["POST"])
|
||||
def xsd():
|
||||
request_data = request.get_json()
|
||||
xml = request_data['data']
|
||||
xsd = request_data['process']
|
||||
|
||||
response = dict()
|
||||
start = time.time_ns()
|
||||
try:
|
||||
response['result'] = Parser.xsd(xml, xsd)
|
||||
response['status'] = "OK"
|
||||
except BaseException as e:
|
||||
response['result'] = str(e)
|
||||
response['status'] = "ERR"
|
||||
finally:
|
||||
exec_time = (time.time_ns() - start) / 10**6
|
||||
response['time'] = f"{exec_time:.03f}"
|
||||
response['processor'] = "libxml2 over lxml"
|
||||
return json.dumps(response)
|
||||
|
||||
@app.route("/xslt", methods=["POST"])
|
||||
def xslt():
|
||||
request_data = request.get_json()
|
||||
xml = request_data['data']
|
||||
xslt = request_data['process']
|
||||
|
||||
response = dict()
|
||||
start = time.time_ns()
|
||||
try:
|
||||
response['result'] = Parser.xslt(xml, xslt)
|
||||
response['status'] = "OK"
|
||||
except BaseException as e:
|
||||
response['result'] = str(e)
|
||||
response['status'] = "ERR"
|
||||
finally:
|
||||
exec_time = (time.time_ns() - start) / 10**6
|
||||
response['time'] = f"{exec_time:.03f}"
|
||||
response['processor'] = "libxml2 over lxml"
|
||||
return json.dumps(response)
|
||||
Reference in New Issue
Block a user