Skip to content

Commit

Permalink
Add old_db_to_provider_dir for using old data
Browse files Browse the repository at this point in the history
  • Loading branch information
foolcage committed Mar 30, 2024
1 parent c2d462f commit 95a2950
Showing 1 changed file with 26 additions and 1 deletion.
27 changes: 26 additions & 1 deletion src/zvt/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import os
import pkgutil
import pprint
import shutil
from logging.handlers import RotatingFileHandler

import pandas as pd
Expand Down Expand Up @@ -164,6 +165,29 @@ def init_plugins():
logger.warning(f"failed to load plugin {name}", e)
logger.info(f"loaded plugins:{_plugins}")

def old_db_to_provider_dir(data_path):
files = os.listdir(data_path)
for file in files:
if file.endswith(".db"):
# Split the file name to extract the provider
provider = file.split('_')[0]

# Define the destination directory
destination_dir = os.path.join(data_path, provider)

# Create the destination directory if it doesn't exist
if not os.path.exists(destination_dir):
os.makedirs(destination_dir)

# Define the source and destination paths
source_path = os.path.join(data_path, file)
destination_path = os.path.join(destination_dir, file)

# Move the file to the destination directory
if not os.path.exists(destination_path):
shutil.move(source_path, destination_path)
logger.info(f"Moved {file} to {destination_dir}")


if os.getenv("TESTING_ZVT"):
init_env(zvt_home=ZVT_TEST_HOME)
Expand All @@ -182,10 +206,11 @@ def init_plugins():

copyfile(DATA_SAMPLE_ZIP_PATH, ZVT_TEST_ZIP_DATA_PATH)
unzip(ZVT_TEST_ZIP_DATA_PATH, ZVT_TEST_DATA_PATH)

else:
init_env(zvt_home=ZVT_HOME)

old_db_to_provider_dir(zvt_env["data_path"])

# register to meta
import zvt.contract as zvt_contract
import zvt.recorders as zvt_recorders
Expand Down

0 comments on commit 95a2950

Please sign in to comment.