Improve existing data check in 'export'

This commit is contained in:
coolneng 2020-01-08 22:40:17 +01:00
parent 16a789cdf9
commit a0a5384e5b
Signed by: coolneng
GPG Key ID: 9893DA236405AF57
1 changed files with 5 additions and 2 deletions

View File

@ -1,3 +1,4 @@
from app.models import Annual_Data, Glacier, User
from database.constants import DB_NAME, DB_PW, DB_USER from database.constants import DB_NAME, DB_PW, DB_USER
from pandas import DataFrame, read_csv from pandas import DataFrame, read_csv
from sqlalchemy import create_engine, engine from sqlalchemy import create_engine, engine
@ -25,8 +26,10 @@ def create_dataframes() -> DataFrame:
def insert_data(df_list, conn): def insert_data(df_list, conn):
if conn.table_names() is not None: models = [Glacier, Annual_Data, User]
return for model in models:
if model.query.first() is not None:
return
for key, value in df_list.items(): for key, value in df_list.items():
value.to_sql(key, con=conn, index=False, if_exists="append") value.to_sql(key, con=conn, index=False, if_exists="append")