-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.py
More file actions
78 lines (58 loc) · 2.36 KB
/
server.py
File metadata and controls
78 lines (58 loc) · 2.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# install poppler: http://blog.alivate.com.au/poppler-windows/
# install pdf2image: pip install pdf2images
# install pyzbar: pip install pyzbar
from flask import Flask, request, jsonify, send_file
import time
import barcode
from pdf import get_pdfinfo_fromfiles, get_page, get_page_filename
app = Flask(__name__)
users = []
messages = []
@app.route("/")
def hello():
return """Use //recognize/<filenames> with | as a path separator"""
@app.route("/status")
def status():
return {"status": True, "name": "Сервер Алексея"}
@app.route("/page/<string:strfilename>/<int:pagenum>", methods=["GET"])
def page(strfilename, pagenum):
filename = strfilename.replace("|", "/")
return send_file(get_page_filename(filename, pagenum))
@app.route("/decode_ean13/<string:strfilename>/<int:pagenum>", methods=["GET"])
def decode_ean13(strfilename, pagenum):
filename = strfilename.replace("|", "/")
imagefilename = get_page_filename(filename, pagenum)
decoded = barcode.decode_ean13(imagefilename)
return jsonify(decoded)
@app.route("/pdfinfo/<string:strfilenames>", methods=["GET"])
def pdfinfo(strfilenames):
# recognize barcode from first page of pdf file or from image,
# accepts file data or file path, accessible by local network
app.logger.debug('pdfinfo')
filenames = strfilenames.split(",")
newfilenames = []
for filename in filenames:
newfilenames.append(filename.replace("|", "/"))
if request.method == "GET":
info = get_pdfinfo_fromfiles(newfilenames)
return jsonify(info), 200
else:
return {"method": "Unsupported"}
@app.route("/recognize/<string:strfilenames>", methods=["GET"])
def recognize(strfilenames):
# recognize barcode from first page of pdf file or from image,
# accepts file data or file path, accessible by local network
app.logger.debug('recognize')
filenames = strfilenames.split(",")
newfilenames = []
for filename in filenames:
newfilenames.append(filename.replace("|", "/"))
if request.method == "GET":
print(request.json)
return {"method": "GET", "filename": newfilenames[0]}
else:
return {"method": "Unsupported"}
@app.route("/pdf2images", methods=["GET", "POST"])
def pdf2images():
return {"method": "Not implemented"}
app.run()