From 3c3ec1e79b00de3c1b6acad2c2d83e51e1fa3c9a Mon Sep 17 00:00:00 2001 From: lance allen Date: Thu, 6 Sep 2018 15:38:35 -0700 Subject: [PATCH] adding routes/views for status reports on devices --- app.py | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/app.py b/app.py index 24cc818..ff9df2a 100644 --- a/app.py +++ b/app.py @@ -10,22 +10,32 @@ from configparser import ConfigParser from pathlib import Path -# Generate routes and views for each device and build the app +# Generate routes and views and build the app def configure_app(): with Configurator() as config: + # Generate routes for devices for device_name in app_config.devices: device_key = app_config.devices[device_name] config.add_route( device_name, - '/device/{}'.format(device_key) + "/device/{}".format(device_key) + ) + config.add_route( + "{}-status".format(device_name), + "/status/{}".format(device_name) ) config.add_view( lambda_functions.ingest, route_name=device_name, - renderer='json' + renderer="json" + ) + config.add_view( + lambda_functions.status, + route_name="{}-status".format(device_name), + renderer="json" ) - app = config.make_wsgi_app() - return app + app = config.make_wsgi_app() + return app # API Gateway/Zappa function handler @@ -35,7 +45,7 @@ def generate_wsgi_app(app, environ): # Local web server for development -if __name__ == '__main__': +if __name__ == "__main__": print("[+] Starting local web server on port 8080...") - server = make_server('0.0.0.0', 8080, configure_app()) + server = make_server("0.0.0.0", 8080, configure_app()) server.serve_forever()