Only parse and export data if needed
This commit is contained in:
parent
f84d71616a
commit
16a789cdf9
|
@ -25,6 +25,8 @@ def create_dataframes() -> DataFrame:
|
|||
|
||||
|
||||
def insert_data(df_list, conn):
|
||||
if conn.table_names() is not None:
|
||||
return
|
||||
for key, value in df_list.items():
|
||||
value.to_sql(key, con=conn, index=False, if_exists="append")
|
||||
|
||||
|
|
|
@ -2,6 +2,7 @@ from iso3166 import countries as co
|
|||
from pandas import DataFrame, concat, read_csv
|
||||
from csv import QUOTE_NONNUMERIC
|
||||
from database.constants import ADMIN_PW
|
||||
from os import path
|
||||
|
||||
|
||||
def country_conversion(political_unit) -> str:
|
||||
|
@ -51,12 +52,12 @@ def rename_fields(df_list):
|
|||
|
||||
|
||||
def create_databases(df):
|
||||
user = {"uid": [7843], "username": ["admin"], "password": [ADMIN_PW]}
|
||||
files = {
|
||||
"glacier": "../data/glacier.csv",
|
||||
"annual_data": "../data/annual_data.csv",
|
||||
"user": "../data/user.csv",
|
||||
}
|
||||
user = {"uid": [7843], "username": ["admin"], "password": [ADMIN_PW]}
|
||||
dataframes = {
|
||||
"glacier": df[["POLITICAL_UNIT", "NAME", "WGMS_ID"]].drop_duplicates(),
|
||||
"annual_data": df[["WGMS_ID", "YEAR", "AREA", "MEDIAN_ELEVATION", "LENGTH"]],
|
||||
|
@ -64,6 +65,8 @@ def create_databases(df):
|
|||
}
|
||||
renamed_dfs = rename_fields(dataframes)
|
||||
for key, val in renamed_dfs.items():
|
||||
if path.isfile(files[key]):
|
||||
continue
|
||||
val.to_csv(files[key], index=False, quoting=QUOTE_NONNUMERIC)
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue