Integrated Label Generation

This commit is contained in:
Jan 2025-07-21 13:10:24 +02:00
parent b89b582520
commit 68ed2ab292
8 changed files with 103 additions and 8 deletions

Binary file not shown.

View file

@ -2,6 +2,8 @@ from flask import Flask, send_from_directory, abort, request
import json import json
import requests import requests
import os import os
import logging
import label
app = Flask(__name__) app = Flask(__name__)
def pretty_print_POST(req): def pretty_print_POST(req):
@ -39,13 +41,21 @@ def download_pre():
except FileNotFoundError: except FileNotFoundError:
abort(404, description="File not found") abort(404, description="File not found")
@app.route('/print', methods=['POST'])
def print_label(): @app.route("/label", methods=["POST"])
url = "http://10.200.4.12:8000/label" def build():
data = request.get_json() typst_bytes = request.get_data()
label = requests.post(url,data=json.dumps(data)).content typst_string = typst_bytes.decode("utf-8")
print(label)
return "{Success}" 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__': if __name__ == '__main__':
app.run(debug=True) app.run(debug=True)

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.9 KiB

View 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)

View 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)

View file

@ -13,6 +13,6 @@ print_data() {
EOF EOF
} }
curl -X POST http://localhost:5000/print \ curl -X POST http://localhost:5000/label \
-H "Content-Type: application/json" \ -H "Content-Type: application/json" \
-d "$(print_data)" -d "$(print_data)"

View file

@ -6,6 +6,8 @@ pkgs.mkShell {
(pkgs.python3.withPackages (ps: with ps; [ (pkgs.python3.withPackages (ps: with ps; [
flask flask
requests requests
typst
pip
])) ]))
]; ];