This repository has been archived on 2019-10-02. You can view files and clone it, but cannot push or open issues or pull requests.
Files
DoorUnlocker/app.py
2019-10-02 15:26:09 +08:00

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)