add functionality to convert internally

This commit is contained in:
WorldTeacher
2024-10-23 10:30:41 +02:00
parent 0f45bb8f57
commit 28efc7388a

View File

@@ -1,6 +1,6 @@
import datetime import datetime
import json import json
from .convert import convert_to_dict
now = datetime.datetime.now().strftime("%Y-%m-%d") now = datetime.datetime.now().strftime("%Y-%m-%d")
@@ -24,6 +24,7 @@ class Transform:
""" """
def __init__(self, data_source): def __init__(self, data_source):
self.data_source = data_source self.data_source = data_source
self.data_type = data_source.split(".")[-1]
self.data = None self.data = None
def load_data(self)->"Transform": def load_data(self)->"Transform":
@@ -32,8 +33,14 @@ class Transform:
Returns: Returns:
self: The instance of the class self: The instance of the class
""" """
with open(self.data_source, "r") as file: match self.data_type:
self.data = json.load(file) case "json":
with open(self.data_source, "r") as file:
self.data = json.load(file)
case "log":
self.data = convert_to_dict(self.data_source)
case _:
raise ValueError("Only JSON and log files are supported")
return self return self
def transform_data( def transform_data(