mirror of
https://codeberg.org/angestoepselt/imagestack.git
synced 2026-03-21 22:32:17 +00:00
Integrated Label Generation
This commit is contained in:
parent
b89b582520
commit
68ed2ab292
8 changed files with 103 additions and 8 deletions
Binary file not shown.
BIN
tools/python_utils/__pycache__/label.cpython-312.pyc
Normal file
BIN
tools/python_utils/__pycache__/label.cpython-312.pyc
Normal file
Binary file not shown.
|
|
@ -2,6 +2,8 @@ from flask import Flask, send_from_directory, abort, request
|
|||
import json
|
||||
import requests
|
||||
import os
|
||||
import logging
|
||||
import label
|
||||
app = Flask(__name__)
|
||||
|
||||
def pretty_print_POST(req):
|
||||
|
|
@ -39,13 +41,21 @@ def download_pre():
|
|||
except FileNotFoundError:
|
||||
abort(404, description="File not found")
|
||||
|
||||
@app.route('/print', methods=['POST'])
|
||||
def print_label():
|
||||
url = "http://10.200.4.12:8000/label"
|
||||
data = request.get_json()
|
||||
label = requests.post(url,data=json.dumps(data)).content
|
||||
print(label)
|
||||
return "{Success}"
|
||||
|
||||
@app.route("/label", methods=["POST"])
|
||||
def build():
|
||||
typst_bytes = request.get_data()
|
||||
typst_string = typst_bytes.decode("utf-8")
|
||||
|
||||
try:
|
||||
j = json.loads(typst_string)
|
||||
except json.JSONDecodeError as e:
|
||||
print(e)
|
||||
return "Failed"
|
||||
|
||||
pdf = label.compile_pdf(j)
|
||||
return "Success"
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
app.run(debug=True)
|
||||
|
|
|
|||
BIN
tools/python_utils/files/logo_stack.png
Normal file
BIN
tools/python_utils/files/logo_stack.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 4.9 KiB |
69
tools/python_utils/files/main.typ
Normal file
69
tools/python_utils/files/main.typ
Normal file
|
|
@ -0,0 +1,69 @@
|
|||
#import "@preview/tiaoma:0.3.0"
|
||||
#set page(width: 89mm, height: 36mm,
|
||||
margin: (
|
||||
top: 2mm,
|
||||
bottom: 2mm,
|
||||
left: 3mm,
|
||||
right: 3mm,
|
||||
))
|
||||
#set text(font: "DejaVu Sans Mono")
|
||||
#let label(computer) = block[
|
||||
|
||||
#table(
|
||||
columns: (2cm,1fr,auto),
|
||||
align: (center,left,center),
|
||||
stroke: 0pt,
|
||||
inset: 0mm,
|
||||
// gutter: 0mm,
|
||||
[#image("logo_stack.png",width: 60%)],
|
||||
[
|
||||
#set text(11pt)
|
||||
angestoepselt e.V. \
|
||||
Passwort: csw \
|
||||
#set text(20pt)
|
||||
#computer.id
|
||||
#set text(10pt)
|
||||
],[
|
||||
#tiaoma.barcode(
|
||||
computer.id,
|
||||
"QRCode",
|
||||
height: 20mm,
|
||||
)
|
||||
]/*,
|
||||
table.cell(colspan: 3)[
|
||||
#set text(8pt)
|
||||
#block(height: 0.5mm)
|
||||
#computer.distribution/#computer.version/#computer.cpu/#computer.memory/#computer.disk/ID:#computer.id
|
||||
] */
|
||||
)
|
||||
|
||||
#set text(10pt)
|
||||
#computer.distribution/#computer.version/#computer.cpu/#computer.memory/#computer.disk/ID:#computer.id
|
||||
]
|
||||
|
||||
#let charger(computer) = block[
|
||||
#table(
|
||||
columns: (2cm,1fr,auto),
|
||||
align: (center,left,center),
|
||||
stroke: 0pt,
|
||||
inset: 1mm,
|
||||
[#image("logo_stack.png",width: 60%)],
|
||||
[
|
||||
#set text(8pt)
|
||||
Ladegerät:\
|
||||
#set text(20pt)
|
||||
#computer.id
|
||||
#set text(8pt)
|
||||
],[
|
||||
#tiaoma.barcode(
|
||||
computer.id,
|
||||
"QRCode",
|
||||
height: 20mm,
|
||||
)
|
||||
]
|
||||
)
|
||||
]
|
||||
|
||||
#let computer = json(bytes(sys.inputs.computer))
|
||||
#label(computer)
|
||||
#charger(computer)
|
||||
14
tools/python_utils/label.py
Normal file
14
tools/python_utils/label.py
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
import typst
|
||||
import json
|
||||
|
||||
|
||||
|
||||
def compile_pdf(data: dict):
|
||||
data = {"computer": json.dumps(data)}
|
||||
try:
|
||||
res = typst.compile(input="files/main.typ", sys_inputs=data)
|
||||
except RuntimeError as e:
|
||||
print(e)
|
||||
print("Error compiling")
|
||||
return False
|
||||
print(res)
|
||||
|
|
@ -13,6 +13,6 @@ print_data() {
|
|||
EOF
|
||||
}
|
||||
|
||||
curl -X POST http://localhost:5000/print \
|
||||
curl -X POST http://localhost:5000/label \
|
||||
-H "Content-Type: application/json" \
|
||||
-d "$(print_data)"
|
||||
|
|
|
|||
|
|
@ -6,6 +6,8 @@ pkgs.mkShell {
|
|||
(pkgs.python3.withPackages (ps: with ps; [
|
||||
flask
|
||||
requests
|
||||
typst
|
||||
pip
|
||||
]))
|
||||
];
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue