Fixed the printing, added init and small API
This commit is contained in:
24
src/main.py
24
src/main.py
@@ -7,7 +7,7 @@
|
||||
# Then we build the web interface, using the simple Jinja2 templating.
|
||||
|
||||
# Following are the librairies we import,
|
||||
from flask import Flask # Used for the web framework
|
||||
from flask import Flask, request # Used for the web framework
|
||||
from printer import Printer # The wrapper for the printer class
|
||||
import toml # Used for the config file parsing
|
||||
import pprint
|
||||
@@ -38,11 +38,10 @@ app.secret_key = configuration_file["secrets"]["flask_secret_key"]
|
||||
vendor_id = configuration_file["printer"]["vendor_id"]
|
||||
device_id = configuration_file["printer"]["device_id"]
|
||||
|
||||
printer = Printer(app)
|
||||
printer = Printer(app,0x04b8, 0x0e28)
|
||||
printer.init_printer()
|
||||
|
||||
|
||||
if not printer.init_printer(vendor_id, device_id):
|
||||
app.logger.error('Could not init printer, aborting.')
|
||||
exit(-1)
|
||||
|
||||
# API routes
|
||||
# The api has the following methods
|
||||
@@ -51,14 +50,21 @@ if not printer.init_printer(vendor_id, device_id):
|
||||
# api/status/{paper,ping,stats}
|
||||
|
||||
# If you just call the api route, you get a help back.
|
||||
@app.route('/')
|
||||
def index():
|
||||
return "Welcome ! Please type your message in the URL bar in such way : /api/print/sms?txt=<message here>"
|
||||
|
||||
|
||||
@app.route('/api')
|
||||
def api_help():
|
||||
return "Welcome to the API's help page"
|
||||
|
||||
@app.route('/api/print')
|
||||
def index():
|
||||
return "Printing..."
|
||||
def api_index():
|
||||
return "Welcome to the printing software's API. Please see the index page to get started."
|
||||
|
||||
@app.route('/api/print/sms')
|
||||
@app.route('/api/print/sms', methods=['GET'])
|
||||
def api_print_sms():
|
||||
return "Printing short message."
|
||||
texte = request.args.get("txt",type=str)
|
||||
app.logger.debug("Printing : " + texte)
|
||||
return printer.print_sms(texte)
|
||||
|
||||
Reference in New Issue
Block a user