add functionality to convert internally
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import datetime
|
||||
import json
|
||||
|
||||
from .convert import convert_to_dict
|
||||
now = datetime.datetime.now().strftime("%Y-%m-%d")
|
||||
|
||||
|
||||
@@ -24,6 +24,7 @@ class Transform:
|
||||
"""
|
||||
def __init__(self, data_source):
|
||||
self.data_source = data_source
|
||||
self.data_type = data_source.split(".")[-1]
|
||||
self.data = None
|
||||
|
||||
def load_data(self)->"Transform":
|
||||
@@ -32,8 +33,14 @@ class Transform:
|
||||
Returns:
|
||||
self: The instance of the class
|
||||
"""
|
||||
with open(self.data_source, "r") as file:
|
||||
self.data = json.load(file)
|
||||
match self.data_type:
|
||||
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
|
||||
|
||||
def transform_data(
|
||||
|
||||
Reference in New Issue
Block a user