Removed old code, added new files in src/ using classes for each moving part.
This commit is contained in:
51
src/main.py
Normal file
51
src/main.py
Normal file
@@ -0,0 +1,51 @@
|
||||
# Welcome to the LittlePrynter's source code.
|
||||
# This program expose a web interface, with user authentification, that makes it possible to print messages from the web.
|
||||
# It also exposes a API, making it possible to print and interface with much of the printer's abilities.
|
||||
|
||||
# We first define the connection to the printer itself,
|
||||
# Then we build the API around Flask,
|
||||
# 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 printer import Printer
|
||||
|
||||
# We define the app module used by Flask
|
||||
app = Flask(__name__)
|
||||
app.secret_key = b'\x98>3nM[D\xa4\xd4\xd0K\xab?oM.`\x98'
|
||||
# TODO: Get this secret key from a config file
|
||||
|
||||
|
||||
# Printer connection
|
||||
# Uses the class defined in the printer.py file
|
||||
|
||||
# Define the USB connections here.
|
||||
# TODO: move this to a config file
|
||||
vendor_id = 0x04b8
|
||||
device_id = 0x0e28
|
||||
|
||||
|
||||
printer = Printer(app)
|
||||
|
||||
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
|
||||
# api/print/{sms,img,letter,qr,barcode}
|
||||
# api/auth/{login,logout}
|
||||
# api/status/{paper,ping,stats}
|
||||
|
||||
# If you just call the api route, you get a help back.
|
||||
@app.route('/api')
|
||||
def api_help():
|
||||
return "Welcome to the API's help page"
|
||||
|
||||
@app.route('/api/print')
|
||||
def index():
|
||||
return "Printing..."
|
||||
|
||||
@app.route('/api/print/sms')
|
||||
def api_print_sms():
|
||||
return "Printing short message."
|
||||
Reference in New Issue
Block a user