web.py 572 B

12345678910111213141516171819202122232425262728293031323334
  1. import json
  2. from flask import Flask
  3. from flask import send_file
  4. from data import dataInstance
  5. app = Flask(__name__)
  6. dao = dataInstance
  7. def web_start(host, port):
  8. app.run(host=host, port=port)
  9. @app.route('/')
  10. def index():
  11. return send_file('static/index.html')
  12. @app.route('/all')
  13. def msg_all():
  14. rows = dao.read_all()
  15. return json.dumps(rows)
  16. @app.route('/from/<addr>')
  17. def msg_from(addr):
  18. rows = dao.read_from(addr)
  19. return json.dumps(rows)
  20. @app.route('/to/<addr>')
  21. def msg_to(addr):
  22. rows = dao.read_to(addr)
  23. return json.dumps(rows)