-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
86 lines (70 loc) · 2.56 KB
/
Copy pathmain.py
File metadata and controls
86 lines (70 loc) · 2.56 KB
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
82
83
84
85
"""
Main application entry point for Excel to Database project
"""
import os
from excel_reader import ExcelReader
from data_processor import DataProcessor
from database import db_manager
from config import Config
def main():
"""Main application function"""
print("Excel to Database Processing Application")
print("=" * 50)
# Initialize database
print("\n1. Initializing database...")
if not db_manager.create_connection():
print("Failed to create database connection. Exiting.")
return
# if not db_manager.create_tables():
# print("Failed to create database tables. Exiting.")
# return
# Initialize Excel reader
print("\n2. Initializing Excel reader...")
excel_reader = ExcelReader()
# Show Excel file information
print("\n3. Excel file information:")
excel_info = excel_reader.get_excel_info()
if 'error' not in excel_info:
print(f" File: {excel_info['file_path']}")
print(f" Sheets available: {excel_info['sheet_names']}")
print(f" Using sheet: {excel_info['current_sheet']}")
print(f" Header row: {excel_info['header_row']}")
else:
print(f" Error: {excel_info['error']}")
return
# Read Excel file
print(f"\n4. Reading Excel file: {excel_reader.file_path}")
if not excel_reader.read_excel_file():
print("Failed to read Excel file. Exiting.")
return
# Show data preview
print("\n5. Data preview:")
excel_reader.preview_data(5)
# Show data info
print("\n6. Data information:")
data_info = excel_reader.get_data_info()
for key, value in data_info.items():
print(f" {key}: {value}")
# Extract data
print("\n7. Extracting data...")
extracted_data = excel_reader.extract_data_by_columns()
if not extracted_data:
print("No data extracted. Exiting.")
return
# Process and save data
print("\n8. Processing and saving data to database...")
data_processor = DataProcessor()
if data_processor.process_and_save_data(extracted_data):
print("Data processing completed successfully!")
# Show summary
print("\n9. Database summary:")
summary = data_processor.get_data_summary()
for table, count in summary.items():
print(f" {table}: {count} records")
else:
print("Data processing failed.")
# Close database connection
db_manager.close_connection()
print("\nApplication completed.")
if __name__ == "__main__":
main()