web.py 713 B

12345678910111213141516171819202122232425262728293031323334
  1. #!/usr/bin/env python3
  2. import json
  3. import urllib
  4. import datetime
  5. from db import db
  6. from flask import Flask, jsonify, request
  7. app = Flask(__name__)
  8. PORT = 8981
  9. BASE_PATH="/back" #changes based on webserver
  10. @app.route(BASE_PATH + '/cliente/<_hash>')
  11. def client(_hash):
  12. out=db().client(_hash)
  13. if out is None:
  14. return "{}", 400
  15. return json.dumps(out)
  16. @app.route(BASE_PATH + '/productos/<_hash>')
  17. def products(_hash):
  18. c=db().client(_hash)
  19. if c is None:
  20. return "{}", 400
  21. out=db().products()
  22. return json.dumps(out)
  23. @app.route(BASE_PATH + '/pedido', methods=["POST"])
  24. def pedido():
  25. t = datetime.date.now()
  26. r = request.get_json()
  27. if __name__ == '__main__':
  28. app.run(host="0.0.0.0",port=PORT, debug=True)