2020-01-09 19:13:24 +01:00
|
|
|
from app import db
|
2020-01-08 22:40:17 +01:00
|
|
|
from app.models import Annual_Data, Glacier, User
|
2020-01-08 01:23:00 +01:00
|
|
|
from pandas import DataFrame, read_csv
|
|
|
|
|
|
|
|
|
2020-01-09 19:13:24 +01:00
|
|
|
def create_dataframes() -> {DataFrame}:
|
2020-01-06 11:12:55 +01:00
|
|
|
files = {
|
|
|
|
"glacier": "../data/glacier.csv",
|
2020-01-08 01:47:12 +01:00
|
|
|
"annual_data": "../data/annual_data.csv",
|
|
|
|
"user": "../data/user.csv",
|
2020-01-06 11:12:55 +01:00
|
|
|
}
|
|
|
|
df_list = {}
|
|
|
|
for csv in files.keys():
|
2020-01-08 01:23:00 +01:00
|
|
|
df_list[csv] = read_csv(files[csv])
|
2020-01-06 11:12:55 +01:00
|
|
|
return df_list
|
2020-01-06 08:31:21 +01:00
|
|
|
|
|
|
|
|
2020-01-09 19:13:24 +01:00
|
|
|
def insert_data(df_list):
|
2020-01-08 22:40:17 +01:00
|
|
|
models = [Glacier, Annual_Data, User]
|
|
|
|
for model in models:
|
|
|
|
if model.query.first() is not None:
|
|
|
|
return
|
2020-01-06 11:12:55 +01:00
|
|
|
for key, value in df_list.items():
|
2020-01-09 19:13:24 +01:00
|
|
|
value.to_sql(key, con=db.engine, index=False, if_exists="append")
|
2020-01-06 08:31:21 +01:00
|
|
|
|
|
|
|
|
|
|
|
def main():
|
2020-01-06 11:12:55 +01:00
|
|
|
df_list = create_dataframes()
|
2020-01-09 19:13:24 +01:00
|
|
|
insert_data(df_list)
|
2020-01-06 08:31:21 +01:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
main()
|