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-05-02 22:54:21 +08:00

33 lines
581 B
Python

import os
from flask import Flask, request, abort, jsonify
import unlocker
PORT = os.environ.get('PORT') or 5000
CODE = os.environ.get('CODE') or '8787'
UNLOCKER_PIN = os.environ.get('UNLOCKER_PIN') or 'XIO-P7'
app = Flask(__name__)
@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.run(UNLOCKER_PIN)
return "OK"
else:
abort(404)
if __name__ == '__main__':
app.run('0.0.0.0', port=PORT)