last
This commit is contained in:
parent
d4ecc354cf
commit
4d7411256b
|
|
@ -0,0 +1,26 @@
|
||||||
|
# For more information, please refer to https://aka.ms/vscode-docker-python
|
||||||
|
FROM python:3.8-slim-buster
|
||||||
|
|
||||||
|
|
||||||
|
EXPOSE 5003
|
||||||
|
|
||||||
|
# Keeps Python from generating .pyc files in the container
|
||||||
|
ENV PYTHONDONTWRITEBYTECODE=1
|
||||||
|
|
||||||
|
# Turns off buffering for easier container logging
|
||||||
|
ENV PYTHONUNBUFFERED=1
|
||||||
|
|
||||||
|
# Install pip requirements
|
||||||
|
COPY requirements.txt .
|
||||||
|
RUN pip install --no-cache-dir -r requirements.txt
|
||||||
|
|
||||||
|
WORKDIR /app
|
||||||
|
COPY . /app
|
||||||
|
|
||||||
|
# Creates a non-root user with an explicit UID and adds permission to access the /app folder
|
||||||
|
# For more info, please refer to https://aka.ms/vscode-docker-python-configure-containers
|
||||||
|
RUN adduser -u 5678 --disabled-password --gecos "" appuser && chown -R appuser /app
|
||||||
|
USER appuser
|
||||||
|
|
||||||
|
# During debugging, this entry point will be overridden. For more information, please refer to https://aka.ms/vscode-docker-python-debug
|
||||||
|
CMD ["python", "test.py"]
|
||||||
|
|
@ -0,0 +1,4 @@
|
||||||
|
[ZoneTransfer]
|
||||||
|
ZoneId=3
|
||||||
|
ReferrerUrl=https://brana.imtts.cz/webmail/
|
||||||
|
HostUrl=https://brana.imtts.cz/webmail/api/download/attachment/imtts.cz/navratil/3582c3e0-1797-492e-b6b6-60c6039c7e90/6369/0-1/body.xlsx?version=38476&sid=60d37f31d4a485d454612aa752d8d91778d4e5b1ac4adddae508fdef42317af8&mode=view
|
||||||
Binary file not shown.
Binary file not shown.
|
|
@ -0,0 +1,12 @@
|
||||||
|
services:
|
||||||
|
test:
|
||||||
|
image: test2
|
||||||
|
build:
|
||||||
|
context: .
|
||||||
|
dockerfile: ./Dockerfile
|
||||||
|
command: ["sh", "-c", "pip install debugpy -t /tmp && python /tmp/debugpy --wait-for-client --listen 0.0.0.0:5678 -m flask run --no-debugger --no-reload --host 0.0.0.0 --port 5002"]
|
||||||
|
ports:
|
||||||
|
- 5002:5002
|
||||||
|
- 5678:5678
|
||||||
|
environment:
|
||||||
|
- FLASK_APP=test.py
|
||||||
|
|
@ -0,0 +1,8 @@
|
||||||
|
services:
|
||||||
|
test:
|
||||||
|
image: test2
|
||||||
|
build:
|
||||||
|
context: .
|
||||||
|
dockerfile: ./Dockerfile
|
||||||
|
ports:
|
||||||
|
- 5003:5003
|
||||||
|
|
@ -0,0 +1,52 @@
|
||||||
|
import ezdxf
|
||||||
|
import openpyxl
|
||||||
|
import os
|
||||||
|
import sys
|
||||||
|
|
||||||
|
def nacti_data_z_excelu(soubor, listname="List1"):
|
||||||
|
wb = openpyxl.load_workbook(soubor, data_only=True)
|
||||||
|
sheet = wb[listname]
|
||||||
|
body = []
|
||||||
|
|
||||||
|
for row in sheet.iter_rows(min_row=2, values_only=True):
|
||||||
|
if row[0] and row[1] is not None and row[2] is not None:
|
||||||
|
label = str(row[0])
|
||||||
|
try:
|
||||||
|
x = float(row[1])
|
||||||
|
y = float(row[2])
|
||||||
|
z = float(row[3]) if len(row) > 3 and row[3] is not None else 0
|
||||||
|
body.append((label, x, y, z))
|
||||||
|
except ValueError:
|
||||||
|
continue
|
||||||
|
return body
|
||||||
|
|
||||||
|
def exportuj_do_dxf(body, vystup):
|
||||||
|
doc = ezdxf.new()
|
||||||
|
msp = doc.modelspace()
|
||||||
|
|
||||||
|
doc.layers.new(name="BODY", dxfattribs={"color": 7})
|
||||||
|
doc.layers.new(name="POPISKY", dxfattribs={"color": 1})
|
||||||
|
|
||||||
|
for label, x, y, z in body:
|
||||||
|
msp.add_point((x, y, z), dxfattribs={"layer": "BODY"})
|
||||||
|
msp.add_text(
|
||||||
|
label,
|
||||||
|
dxfattribs={"layer": "POPISKY"}).set_pos((x + 2, y + 2), align="LEFT") # Posun textu od bodu
|
||||||
|
|
||||||
|
doc.saveas(vystup)
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
if len(sys.argv) != 3:
|
||||||
|
print("Použití: python excel_to_dxf_hotovy.py vstup.xlsx vystup.dxf")
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
excel_soubor = sys.argv[1]
|
||||||
|
vystup_nazev = sys.argv[2]
|
||||||
|
|
||||||
|
slozka = os.path.dirname(os.path.abspath(__file__))
|
||||||
|
excel_cesta = os.path.join(slozka, excel_soubor)
|
||||||
|
vystup_cesta = os.path.join(slozka, vystup_nazev)
|
||||||
|
|
||||||
|
body = nacti_data_z_excelu(excel_cesta)
|
||||||
|
exportuj_do_dxf(body, vystup_cesta)
|
||||||
|
print(f"Soubor {vystup_nazev} byl úspěšně vytvořen ve složce: {slozka}")
|
||||||
|
|
@ -0,0 +1,14 @@
|
||||||
|
blinker==1.8.2
|
||||||
|
click==8.1.8
|
||||||
|
et-xmlfile==2.0.0
|
||||||
|
ezdxf==0.17
|
||||||
|
flask==3.0.3
|
||||||
|
importlib-metadata==8.5.0
|
||||||
|
itsdangerous==2.2.0
|
||||||
|
jinja2==3.1.6
|
||||||
|
markupsafe==2.1.5
|
||||||
|
openpyxl==3.1.5
|
||||||
|
pyparsing==3.1.4
|
||||||
|
typing-extensions==4.13.2
|
||||||
|
werkzeug==3.0.6
|
||||||
|
zipp==3.20.2
|
||||||
|
|
@ -0,0 +1,46 @@
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
|
<!-- apply pico css-->
|
||||||
|
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@picocss/pico@1/css/pico.min.css">
|
||||||
|
<!-- apply htmx -->
|
||||||
|
<script src="https://unpkg.com/htmx.org@1.7.0"></script>
|
||||||
|
<title>converter</title>
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<body>
|
||||||
|
<header class="container"><h1>XLSX to DXF Converter</h1></header>
|
||||||
|
<main class="container">
|
||||||
|
<form action="" method="post" enctype="multipart/form-data">
|
||||||
|
<input type="file" id="file-input" name="file" accept=".xls, .csv, .xlsx" required>
|
||||||
|
<p class="grid">
|
||||||
|
<label for="range">Velikost textu
|
||||||
|
</label>
|
||||||
|
<input type="range" min="0.5" max="10" value="1" step="0.5" id="range" name="range">
|
||||||
|
|
||||||
|
<label id="font_size">1</label>
|
||||||
|
</p>
|
||||||
|
<!-- make submit possible only if file is choosen -->
|
||||||
|
<input type="submit" id="submit-button" value="Nahrát a stáhnout hotový">
|
||||||
|
|
||||||
|
</form>
|
||||||
|
</main>
|
||||||
|
</body>
|
||||||
|
<script>
|
||||||
|
document.getElementById('range').addEventListener('input', function() {
|
||||||
|
document.getElementById('font_size').innerText = this.value;
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
<style>
|
||||||
|
#font_size {
|
||||||
|
margin-left: 10px;
|
||||||
|
padding-bottom: 5px;
|
||||||
|
font-size: 24px;
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
|
||||||
|
</html>
|
||||||
|
|
||||||
|
|
@ -0,0 +1,78 @@
|
||||||
|
from flask import Flask, request, render_template, send_file
|
||||||
|
from io import BytesIO, StringIO
|
||||||
|
import ezdxf
|
||||||
|
import openpyxl
|
||||||
|
import os
|
||||||
|
import sys
|
||||||
|
|
||||||
|
app = Flask(__name__)
|
||||||
|
|
||||||
|
@app.route('/', methods=['GET', 'POST'])
|
||||||
|
def upload_file():
|
||||||
|
if request.method == 'POST':
|
||||||
|
file = request.files['file']
|
||||||
|
if file.filename.endswith('.xls') or file.filename.endswith('.csv') or file.filename.endswith('.xlsx'):
|
||||||
|
# Create a text file with the uploaded file name
|
||||||
|
|
||||||
|
velikost = request.form['range']
|
||||||
|
print(velikost)
|
||||||
|
|
||||||
|
body = nacti_data_z_excelu(file)
|
||||||
|
#print(body)
|
||||||
|
|
||||||
|
dxf_file = exportuj_do_dxf(body, velikost)
|
||||||
|
dxf_file.seek(0)
|
||||||
|
return send_file(
|
||||||
|
path_or_file=dxf_file,
|
||||||
|
as_attachment=True,
|
||||||
|
download_name='hotovy.dxf',
|
||||||
|
mimetype='application/octet-stream'
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
return render_template('upload_form.html', no_file=True)
|
||||||
|
return render_template('upload_form.html')
|
||||||
|
|
||||||
|
def nacti_data_z_excelu(soubor, listname="List1"):
|
||||||
|
wb = openpyxl.load_workbook(soubor, data_only=True)
|
||||||
|
sheet = wb[listname]
|
||||||
|
body = []
|
||||||
|
|
||||||
|
for row in sheet.iter_rows(min_row=2, values_only=True):
|
||||||
|
if row[0] and row[1] is not None and row[2] is not None:
|
||||||
|
label = str(row[0])
|
||||||
|
try:
|
||||||
|
x = float(row[1])
|
||||||
|
y = float(row[2])
|
||||||
|
z = float(row[3]) if len(row) > 3 and row[3] is not None else 0
|
||||||
|
body.append((label, x, y, z))
|
||||||
|
except ValueError:
|
||||||
|
continue
|
||||||
|
return body
|
||||||
|
|
||||||
|
def exportuj_do_dxf(body, velikost) -> BytesIO:
|
||||||
|
doc = ezdxf.new()
|
||||||
|
msp = doc.modelspace()
|
||||||
|
|
||||||
|
doc.layers.new(name="BODY", dxfattribs={"color": 7})
|
||||||
|
doc.layers.new(name="POPISKY", dxfattribs={"color": 1})
|
||||||
|
|
||||||
|
for label, x, y, z in body:
|
||||||
|
msp.add_point((x, y, z), dxfattribs={"layer": "BODY"})
|
||||||
|
msp.add_text(
|
||||||
|
label + "*"*(body.count((label, x, y, z))-1),
|
||||||
|
|
||||||
|
dxfattribs={"layer": "POPISKY", "height": float(velikost)}).set_pos((x + 2, y + 2), align="LEFT") # Posun textu od bodu
|
||||||
|
|
||||||
|
my_file = StringIO()
|
||||||
|
out_file = BytesIO()
|
||||||
|
doc.write(my_file, fmt="asc")
|
||||||
|
print(my_file)
|
||||||
|
out_file.write(my_file.getvalue().encode('utf-8'))
|
||||||
|
|
||||||
|
return out_file
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
app.run(debug=False, port=5003, host='0.0.0.0')
|
||||||
Loading…
Reference in New Issue