From edc36531c0be68cd7ef418278889681a4807b912 Mon Sep 17 00:00:00 2001 From: 5okin Date: Sun, 24 Jan 2021 17:32:50 +0000 Subject: [PATCH] Upload files to 'server/app' --- server/app/__init__.py | 7 +++++++ server/app/views.py | 31 +++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+) create mode 100644 server/app/__init__.py create mode 100644 server/app/views.py diff --git a/server/app/__init__.py b/server/app/__init__.py new file mode 100644 index 0000000..b3d6e9b --- /dev/null +++ b/server/app/__init__.py @@ -0,0 +1,7 @@ +from flask import Flask, Blueprint + + +#Create flask instance +app = Flask(__name__) + +from . import views diff --git a/server/app/views.py b/server/app/views.py new file mode 100644 index 0000000..6ab7a01 --- /dev/null +++ b/server/app/views.py @@ -0,0 +1,31 @@ +import json +from flask import Flask, request, url_for, render_template +from flask_restful import Resource, Api +from app.services import data_process, database_handle +from flask_pymongo import PyMongo +from app import app + + +#Create the API +API = Api(app) + +#Keeps every measurment received by server for 5 min. +MEASUREMENTS = [] + + +@app.route("/") +def index(): + return render_template('index.html', data=MEASUREMENTS) + + +class ReceiveMeasurments(Resource): + '''Receives and handles data send to api''' + + def put(self): + new_data = json.loads(request.get_json()) + MEASUREMENTS.append(new_data.copy()) + data_process.process(MEASUREMENTS) + database_handle.send_data(new_data.copy()) + return 200 + +API.add_resource(ReceiveMeasurments, '/api/send')