Skip to content
Snippets Groups Projects
Commit c612a4ca authored by Clemens Berteld's avatar Clemens Berteld
Browse files

Creating DB and filling it with data should be working now

parent f4a7792b
No related branches found
No related tags found
No related merge requests found
......@@ -24,7 +24,6 @@ param_postgres = cfg["POSTGRES"]
param_interpol = cfg["INTERPOLATION"]
stationGPD = None
# get_average_data_for_point(52.5, 13.4)
# Create DB "temperatures_berteld_morstein"
def create_db(cursor, db_name):
......@@ -68,6 +67,7 @@ def check_for_db_existence(cursor, db_name):
create_db(cursor, db_name)
return False
def check_for_stations_existence(cursor, table_name):
query = sql.SQL("SELECT * FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = '{}'".format(table_name))
try:
......@@ -77,6 +77,7 @@ def check_for_stations_existence(cursor, table_name):
except(Exception, psycopg2.DatabaseError):
return False
# Connect to DB "temperatures_berteld_morstein" to create table "temperatures". Also installs PostGIS
def create_table(station_list, cursor):
print('Creating table stations')
......@@ -208,13 +209,13 @@ def export(station_list):
with connection.cursor() as cursor:
new_db = False if check_for_db_existence(cursor, db_name) else True
station_exists = False
# station_exists = False
connection = psycopg2.connect(database=db_name, user=user, password=pw, host=param_postgres["host"], port=port)
connection.set_isolation_level(ISOLATION_LEVEL_AUTOCOMMIT) # Needs to be in AUTOCOMMIT mode for creating database
with connection.cursor() as cursor:
station_exists = check_for_stations_existence(cursor, "stations")
# station_exists = check_for_stations_existence(cursor, "stations")
if station_exists == False:
if new_db:
create_table(station_list, cursor)
insert_data(station_list, cursor)
......@@ -222,8 +223,8 @@ def export(station_list):
# connection = psycopg2.connect(database=db_name, user=user, password=pw, host=param_postgres["host"], port=port,
# keepalives=1, keepalives_idle=30, keepalives_interval=10, keepalives_count=5)
with connection.cursor() as cursor:
create_matrix_data(cursor, amount_points)
with connection.cursor() as cursor:
create_matrix_data(cursor, amount_points)
print('Installation successful. You can run the api.py now.')
except(Exception, psycopg2.DatabaseError) as error:
......
This diff is collapsed.
This diff is collapsed.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment