Added example with Docker and Flask (#519)

* Added example with Docker and Flask

* set flask debug flag to False

* new line at the end of file

* format with black

---------

Co-authored-by: Ricardo Sanchez Alba <r2sanchezalba@gmail.com>
This commit is contained in:
Ricardo Sánchez Alba 2023-05-18 07:06:06 -06:00 committed by GitHub
parent 2b826aa834
commit 66348ccc0a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 77 additions and 0 deletions

View File

@ -0,0 +1,28 @@
# Use the official Python image as the base image
FROM python:3.9-slim
# Set the working directory
WORKDIR /app
# Copy the requirements file
COPY requirements.txt .
#Install the libcups library
RUN apt-get update -y && apt-get install libcups2-dev -y
# Install the Python packages
RUN pip install --no-cache-dir -r requirements.txt
RUN pip install python-escpos --pre
# Install Git
RUN apt-get update && \
apt-get install -y git && \
rm -rf /var/lib/apt/lists/*
# Copy the Flask app
COPY app.py .
# Expose the port the Flask app will run on
EXPOSE 8080
# Run the Flask app
CMD ["python", "app.py"]

View File

@ -0,0 +1,6 @@
Simple example on how to use it inside a web service
```
docker build . -t escpos-web
docker run --network=host -p 9999:9999 escpos
```

View File

@ -0,0 +1,22 @@
import escpos
from escpos.printer import *
from flask import Flask, jsonify, request, redirect, session, url_for
import sys
from io import BytesIO
# Initialize Flask app
app = Flask(__name__)
@app.route("/", methods=["GET"])
def do_print():
# p = Usb(0x04b8, 0x0e28, 0)
p = CupsPrinter(host="localhost", port=631, printer_name="TM-T20III")
p.text("Hello World\n")
p.cut()
p.close()
return "OK"
if __name__ == "__main__":
app.run(debug=False, host="0.0.0.0", port=9999)

View File

@ -0,0 +1,21 @@
appdirs==1.4.4
argcomplete==3.0.8
blinker==1.6.2
click==8.1.3
Flask==2.3.2
future==0.18.3
itsdangerous==2.1.2
Jinja2==3.1.2
MarkupSafe==2.1.2
Pillow==9.5.0
pycups==2.0.1
pypng==0.20220715.0
pyserial==3.5
python-barcode==0.14.0
python-escpos==3.0a9
pyusb==1.2.1
PyYAML==6.0
qrcode==7.4.2
six==1.16.0
typing_extensions==4.5.0
Werkzeug==2.3.4