app.py 959 B

12345678910111213141516171819202122232425262728293031323334353637
  1. from flask import Flask, jsonify
  2. from PN532data import readChip
  3. import webbrowser
  4. from threading import Timer
  5. from flask import render_template
  6. from flask_cors import CORS
  7. app = Flask(__name__)
  8. CORS(app, resources=r'/*')
  9. @app.route('/readChip')
  10. def read_chip():
  11. try:
  12. result = readChip()
  13. print(result)
  14. return jsonify({'code': 200, 'msg': '读取成功',
  15. 'data': {'list': result[0], 'chipNumber': result[1], 'vaccinationCipher': result[2],
  16. 'id': result[3]}})
  17. except Exception as e:
  18. print(e)
  19. return jsonify({'code': 500, 'msg': '请见检查芯片是否放好或读卡器连接是否正常'})
  20. @app.route('/')
  21. def index():
  22. return render_template('index.html')
  23. def open_browser():
  24. webbrowser.open_new('http://127.0.0.1:9000')
  25. if __name__ == '__main__':
  26. # Timer(1, open_browser).start()
  27. app.run(port=9000, debug=True, host='0.0.0.0')