Added support for vinted labels
All checks were successful
DNSControl / build (push) Successful in 3m26s
All checks were successful
DNSControl / build (push) Successful in 3m26s
This commit is contained in:
parent
125d6eaf7c
commit
ef3421ff97
4 changed files with 54 additions and 3 deletions
6
cli.py
6
cli.py
|
@ -1,13 +1,13 @@
|
||||||
#! /usr/bin/env python3
|
#! /usr/bin/env python3
|
||||||
from sys import argv
|
from sys import argv
|
||||||
from convert import convert_dhl, convert_hermes
|
from convert import *
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
if len(argv) != 3:
|
if len(argv) != 3:
|
||||||
print("Usage:")
|
print("Usage:")
|
||||||
print("./cli.py <method> <id>")
|
print("./cli.py <method> <id>")
|
||||||
print("Method can be 'hermes' or 'dhl'")
|
print("Method can be 'hermes', 'dhl' or 'vinted'")
|
||||||
exit(1)
|
exit(1)
|
||||||
|
|
||||||
method = argv[1]
|
method = argv[1]
|
||||||
|
@ -18,6 +18,8 @@ if __name__ == "__main__":
|
||||||
convert_dhl(id)
|
convert_dhl(id)
|
||||||
case "hermes":
|
case "hermes":
|
||||||
convert_hermes(id)
|
convert_hermes(id)
|
||||||
|
case "vinted":
|
||||||
|
convert_vinted(id)
|
||||||
case _:
|
case _:
|
||||||
print("Unknown method")
|
print("Unknown method")
|
||||||
|
|
||||||
|
|
24
convert.py
24
convert.py
|
@ -50,3 +50,27 @@ def convert_hermes(id):
|
||||||
|
|
||||||
with open(f"./downloads/{id}.pdf", "wb") as fh:
|
with open(f"./downloads/{id}.pdf", "wb") as fh:
|
||||||
writer.write(fh)
|
writer.write(fh)
|
||||||
|
|
||||||
|
def convert_vinted(id):
|
||||||
|
with open(f"./uploads/{id}.pdf", "rb") as fh:
|
||||||
|
reader = PdfReader(fh)
|
||||||
|
writer = PdfWriter()
|
||||||
|
|
||||||
|
numPages = len(reader.pages)
|
||||||
|
if numPages != 1:
|
||||||
|
exit(1)
|
||||||
|
|
||||||
|
#page = reader.pages[0].rotate(90)
|
||||||
|
page = reader.pages[0]
|
||||||
|
|
||||||
|
left = 18
|
||||||
|
bottom = 150
|
||||||
|
right = 315
|
||||||
|
# calculate last value to get a 3:2 rectangle
|
||||||
|
top = bottom+((right-left)/2)*3
|
||||||
|
|
||||||
|
page.mediabox = RectangleObject((left, bottom,right,top))
|
||||||
|
writer.add_page(page)
|
||||||
|
|
||||||
|
with open(f"./downloads/{id}.pdf", "wb") as fh:
|
||||||
|
writer.write(fh)
|
||||||
|
|
17
main.py
17
main.py
|
@ -3,7 +3,7 @@ from bottle import route, request, static_file, run, redirect, HTTPResponse, hoo
|
||||||
from random import randint
|
from random import randint
|
||||||
from os import remove
|
from os import remove
|
||||||
|
|
||||||
from convert import convert_dhl, convert_hermes
|
from convert import *
|
||||||
|
|
||||||
@route('/')
|
@route('/')
|
||||||
def root():
|
def root():
|
||||||
|
@ -39,6 +39,21 @@ def hermes():
|
||||||
|
|
||||||
return redirect(f"/download/{id}")
|
return redirect(f"/download/{id}")
|
||||||
|
|
||||||
|
@route('/vinted', method='POST')
|
||||||
|
def vinted():
|
||||||
|
upload = request.files.get('upload')
|
||||||
|
if upload.content_type != "application/pdf":
|
||||||
|
return HTTPResponse(status=400, body="Bad file")
|
||||||
|
|
||||||
|
id = randint(100000,999999)
|
||||||
|
upload.save(f"./uploads/{id}.pdf")
|
||||||
|
convert_vinted(id)
|
||||||
|
print(f"converted {upload.filename} as {id}.pdf")
|
||||||
|
# delete upload file
|
||||||
|
remove(f"./uploads/{id}.pdf")
|
||||||
|
|
||||||
|
return redirect(f"/download/{id}")
|
||||||
|
|
||||||
@route('/download/<id>')
|
@route('/download/<id>')
|
||||||
def download(id):
|
def download(id):
|
||||||
filename = f"{id}.pdf"
|
filename = f"{id}.pdf"
|
||||||
|
|
|
@ -22,6 +22,7 @@
|
||||||
<button>Convert!</button>
|
<button>Convert!</button>
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="variant_box">
|
<div class="variant_box">
|
||||||
<b>Variante 2</b><br>
|
<b>Variante 2</b><br>
|
||||||
Hermes Paketschein DIN A4 → 100mmx150mm
|
Hermes Paketschein DIN A4 → 100mmx150mm
|
||||||
|
@ -30,6 +31,15 @@
|
||||||
<button>Convert!</button>
|
<button>Convert!</button>
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div class="variant_box">
|
||||||
|
<b>Variante 3</b><br>
|
||||||
|
Vinted Paketschein DIN A4 → 100mmx150mm
|
||||||
|
<form action="/vinted" method="post" enctype="multipart/form-data">
|
||||||
|
<input name="upload" type="file" size="50" accept="application/pdf">
|
||||||
|
<button>Convert!</button>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
</main>
|
</main>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue