From 3b69b840000bc9ee5e33d89cdc6271e6e5cb8ec0 Mon Sep 17 00:00:00 2001 From: Clemens Berteld <clemens@berteld.com> Date: Sun, 5 Sep 2021 16:45:59 +0200 Subject: [PATCH] Initial API commit --- dataacquisition/ExportToDatabase.py | 5 ++--- dataacquisition/api.py | 23 +++++++++++++++++++++++ 2 files changed, 25 insertions(+), 3 deletions(-) create mode 100644 dataacquisition/api.py diff --git a/dataacquisition/ExportToDatabase.py b/dataacquisition/ExportToDatabase.py index 544ecff..e451cde 100644 --- a/dataacquisition/ExportToDatabase.py +++ b/dataacquisition/ExportToDatabase.py @@ -67,6 +67,8 @@ def insert_data(stationList): with connection.cursor() as cursor: if len(stationList) > 0: + cursor.execute("DELETE FROM stations;") + df_columns = list(stationList) # create (col1,col2,...) @@ -89,6 +91,3 @@ def insert_data(stationList): def export(stationList): check_for_db_existence(stationList) insert_data(stationList) - - # return stationList - diff --git a/dataacquisition/api.py b/dataacquisition/api.py new file mode 100644 index 0000000..c72dc1d --- /dev/null +++ b/dataacquisition/api.py @@ -0,0 +1,23 @@ +import json + +import psycopg2 +from flask import Flask, jsonify +from psycopg2 import sql + +app = Flask(__name__) +app.config['ENV'] = "development" +app.config['DEBUG'] = True +# Testing: Exceptions are propagated rather than handled by the the app’s error handlers. Extensions may also change their behavior to facilitate easier testing. You should enable this in your own tests. +app.config['TESTING'] = False + + +@app.route('/') +def index(): + with psycopg2.connect(database='temperatures_berteld_morstein', user='postgres', password='postgres', host='localhost', port=5432) as connection: + with connection.cursor() as cursor: + # query = sql.SQL("""CREATE TABLE stations ({});""".format(columns_clean)) + pass + return jsonify({'läuft': 'jo'}) + + +app.run(host='127.0.0.1', port=42000) -- GitLab