Making it so all csv is parsed
This commit is contained in:
@@ -1,12 +1,40 @@
|
||||
import os
|
||||
import csv
|
||||
import shutil
|
||||
from data.db_connect import Database
|
||||
|
||||
class Importer:
|
||||
def __init__(self, database: Database):
|
||||
self.database = database
|
||||
|
||||
def parse_all_data(self):
|
||||
pass
|
||||
def parse_all_data(self, source_dir, dest_dir):
|
||||
# Ensure the destination directory exists
|
||||
if not os.path.exists(dest_dir):
|
||||
os.makedirs(dest_dir)
|
||||
|
||||
# List all files in the source and destination directories
|
||||
source_files = set(os.listdir(source_dir))
|
||||
for filename in os.listdir(dest_dir):
|
||||
if filename.endswith('.csv'):
|
||||
source_files.discard(filename)
|
||||
|
||||
dest_files = set(os.listdir(dest_dir))
|
||||
|
||||
# Find files that are in the source but not in the destination
|
||||
missing_files = source_files - dest_files
|
||||
|
||||
# Copy any missing CSV files from the source directory to the destination directory
|
||||
for filename in missing_files:
|
||||
src_file = os.path.join(source_dir, filename)
|
||||
dest_file = os.path.join(dest_dir, filename)
|
||||
|
||||
self.parse_one_file(f"{source_dir}/{filename}")
|
||||
|
||||
try:
|
||||
shutil.copy(src_file, dest_file)
|
||||
print(f"Copied {filename} to {dest_dir}")
|
||||
except Exception as e:
|
||||
print(f"Failed to copy {filename}: {e}")
|
||||
|
||||
def parse_one_file(self, filepath):
|
||||
bb_dict = {}
|
||||
@@ -17,13 +45,6 @@ class Importer:
|
||||
for game in bb_dict:
|
||||
self.populate_database_with_stats(game)
|
||||
|
||||
|
||||
def parse_one_line(self, line):
|
||||
pass
|
||||
|
||||
def parse_last_line_of_file(self, filepath):
|
||||
pass
|
||||
|
||||
def populate_database_with_stats(self, game_stats):
|
||||
insert_game = """
|
||||
INSERT INTO games
|
||||
|
||||
Reference in New Issue
Block a user