33 lines
626 B
Python
33 lines
626 B
Python
import os
|
|
from flask import Flask, request, abort, jsonify
|
|
from chip_unlocker import ChipUnlocker
|
|
|
|
PORT = os.environ.get('PORT') or 5000
|
|
CODE = os.environ.get('CODE') or '8787'
|
|
UNLOCK_PIN = os.environ.get('UNLOCK_PIN') or 'XIO-P7'
|
|
|
|
app = Flask(__name__)
|
|
unlocker = ChipUnlocker(UNLOCK_PIN)
|
|
|
|
|
|
@app.route('/')
|
|
def root():
|
|
return jsonify({
|
|
'message': "Welcome to my door!",
|
|
})
|
|
|
|
|
|
@app.route('/unlock')
|
|
def unlock():
|
|
code = request.args.get('code')
|
|
|
|
if (code == CODE):
|
|
unlocker.unlock()
|
|
return "OK"
|
|
else:
|
|
abort(404)
|
|
|
|
|
|
if __name__ == '__main__':
|
|
app.run('0.0.0.0', port=PORT)
|