您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

35 行
815 B

  1. """
  2. Basic HTTP server to receive and save gps positions sent by Arduino GPS Tracker
  3. """
  4. import falcon
  5. class RequireCSV:
  6. def process_request(self, req, resp):
  7. if req.method in ('POST', 'PUT'):
  8. if 'text/csv' not in req.content_type:
  9. raise falcon.HTTPUnsupportedMediaType('Only CSV is supported')
  10. class PositionsResource:
  11. def on_post(self, req, resp):
  12. data = req.bounded_stream.read()
  13. resp.body = data
  14. resp.status = falcon.HTTP_201
  15. positions = PositionsResource()
  16. api = falcon.API(middleware=[
  17. RequireCSV()
  18. ])
  19. api.add_route('/positions', positions)
  20. if __name__ == "__main__":
  21. # Use python built-in WSGI reference implemention to run a web server
  22. from wsgiref.simple_server import make_server
  23. print('Starting web server...')
  24. srv = make_server('localhost', 8080, api)
  25. srv.serve_forever()