mirror of
https://github.com/python-escpos/python-escpos
synced 2025-07-15 08:43:30 +00:00
Added example with Docker and Flask
This commit is contained in:
parent
2b826aa834
commit
27766b2478
28
examples/docker-flask/Dockerfile
Normal file
28
examples/docker-flask/Dockerfile
Normal 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"]
|
6
examples/docker-flask/README.md
Normal file
6
examples/docker-flask/README.md
Normal 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
|
||||
```
|
20
examples/docker-flask/app.py
Normal file
20
examples/docker-flask/app.py
Normal file
@ -0,0 +1,20 @@
|
||||
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=True, host='0.0.0.0', port=9999)
|
21
examples/docker-flask/requirements.txt
Normal file
21
examples/docker-flask/requirements.txt
Normal 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
|
Loading…
x
Reference in New Issue
Block a user