-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
81 lines (59 loc) Β· 3.03 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# Example usage
import os
import pandas as pd
from csv_structure_provider import list_quest_files_for_language, Config, list_quest_files_for_eng, \
list_cutscene_files_for_eng, list_quest_files_for_jp, list_cutscene_files_for_jp
from database_provider import connect_to_db
from sql_provider import create_table_from_df, insert_data_from_df, insert_data_from_df_with_japanese
def process_csv_files():
conn = connect_to_db()
#TODO: This is repetitive. Please clean up, perhaps by making the list_(language) files to return a list of files, not a directory.
files = list_quest_files_for_eng(Config.BASE_CSV_DIR)
for file_path in files:
if os.path.isfile(file_path) and file_path.endswith(".csv"):
print(f"Processing file: {file_path}")
table_name = os.path.splitext(os.path.basename(file_path))[0]
df = pd.read_csv(file_path)
create_table_from_df(df, table_name, conn)
insert_data_from_df(df, table_name, conn)
print(f"Processed {file_path} into table {table_name}.")
files = list_cutscene_files_for_eng(Config.BASE_CSV_DIR)
for file_path in files:
if os.path.isfile(file_path) and file_path.endswith(".csv"):
print(f"Processing file: {file_path}")
table_name = os.path.splitext(os.path.basename(file_path))[0]
df = pd.read_csv(file_path)
create_table_from_df(df, table_name, conn)
insert_data_from_df(df, table_name, conn)
print(f"Processed {file_path} into table {table_name}.")
#TODO: This is repetitive. Please clean up, perhaps by making the list_(language) files to return a list of files, not a directory.
# Jp should not make a new table.
print("~~~Starting JP files~~~")
files = list_quest_files_for_jp(Config.BASE_CSV_DIR)
for file_path in files:
if os.path.isfile(file_path) and file_path.endswith(".csv"):
print(f"Processing file: {file_path}")
table_name = os.path.splitext(os.path.basename(file_path))[0]
df = pd.read_csv(file_path)
insert_data_from_df_with_japanese(df, table_name, conn)
print(f"Processed {file_path} into table {table_name}.")
files = list_cutscene_files_for_jp(Config.BASE_CSV_DIR)
for file_path in files:
if os.path.isfile(file_path) and file_path.endswith(".csv"):
print(f"Processing file: {file_path}")
table_name = os.path.splitext(os.path.basename(file_path))[0]
df = pd.read_csv(file_path)
insert_data_from_df_with_japanese(df, table_name, conn)
print(f"Processed {file_path} into table {table_name}.")
conn.close()
import time
if __name__ == "__main__":
base_dir = r'C:\Users\sbelknap\PycharmProjects\dialogdbconn\rsrc\csv'
Config.initialize_language_base_directories(base_dir)
start_time = time.time()
# Main method.
process_csv_files()
# # #
end_time = time.time()
elapsed_time = end_time - start_time
print(f"Elapsed time: {elapsed_time:.2f} seconds")