from constants import DB_NAME, DB_PW, DB_USER from pandas import DataFrame, read_csv from sqlalchemy import create_engine, engine def create_connection() -> engine: host = "localhost:3306" connection_uri = "mysql+pymysql://{user}:{pw}@{url}/{db}".format( user=DB_USER, pw=DB_PW, url=host, db=DB_NAME ) engine = create_engine(connection_uri) return engine def create_dataframes() -> DataFrame: files = { "glacier": "../data/glacier.csv", "annual__data": "../data/annual_data.csv", "annual__change": "../data/annual_change.csv", "users": "../data/users.csv", } df_list = {} for csv in files.keys(): df_list[csv] = read_csv(files[csv]) return df_list def insert_data(df_list, conn): for key, value in df_list.items(): value.to_sql(key, con=conn, index=False, if_exists="append", chunksize=1) def main(): conn = create_connection() df_list = create_dataframes() insert_data(df_list, conn) if __name__ == "__main__": main()