summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--common/core.py65
-rw-r--r--modules/telegraf/testing.py17
-rw-r--r--requirements.txt1
3 files changed, 10 insertions, 73 deletions
diff --git a/common/core.py b/common/core.py
index 7fd8cff..c3e3495 100644
--- a/common/core.py
+++ b/common/core.py
@@ -27,8 +27,10 @@ def ask_digit_input(max_index):
print(f" Number ei kuulu valikusse. Palun vali number vahemikus 0-{max_index}.")
-## Checks if api url is correct, if so then returns the json
def is_app_url_correct(api_url, needs_auth, username,passwd):
+ """"
+ Checks if api url is correct, if so then returns the json
+ """"
print("Teostan API kutset...\n")
try:
if needs_auth:
@@ -52,9 +54,10 @@ def is_app_url_correct(api_url, needs_auth, username,passwd):
return None, False
-## TODO - add list level support with porcessors etc
-## Asks the user json item to extract and returns it as dict item-value pair, where item is name and value json path
def inspect_json_top_level(json_data):
+ """"
+ Asks the user json item to extract and returns it as dict item-value pair, where item is name and value json path
+ """"
path = ""
while True:
@@ -90,60 +93,10 @@ def inspect_json_top_level(json_data):
-
-
-###### Other option ##########
-
-def inspect_json_top_level_test(json_data, has_list=False):
- path = ""
- last_key = "value" #Placeholder
-
- while True:
- print(json.dumps(json_data, indent=2))
- print("\nVali json võti või indeks millest soovid väärtuse andmekonveieriga ekstrakteerida\n")
-
- if isinstance(json_data, dict):
- keys = list(json_data.keys())
- for index, key in enumerate(keys):
- value = json_data[key]
- value_type = type(value).__name__
- suggestion = "SplitJson" if isinstance(value, list) else "EvaluateJsonPath"
- print(f" [{index}] {key} ({value_type}) → {suggestion}")
-
- selected_index = ask_digit_input(len(keys) - 1)
- selected_key = keys[selected_index]
- selected_value = json_data[selected_key]
- path += "." + selected_key
- last_key = selected_key
-
- elif isinstance(json_data, list):
- has_list = True
- for index, item in enumerate(json_data):
- item_type = type(item).__name__
- print(f" [{index}] [{item_type}]")
-
- selected_index = ask_digit_input(len(json_data) - 1)
- selected_value = json_data[selected_index]
- path += f"[{selected_index}]"
- last_key = str(selected_index)
-
- else:
- # Primitive value, nothing to dive into
- print(f"\nLõppväärtus: {json_data}")
- return {last_key: path}
-
-
-
- if isinstance(selected_value, (dict, list)):
- json_data = selected_value
- else:
- #print(f"\nValitud väärtus: '{selected_value}'")
- print(f"\nValitud väärtus: '{path}'")
- return {last_key: path}
-
-
def get_data_values():
-
+ """
+ Interaktiivse moodi jaoks. Võimaldab kasutajal parsida API json vastust, et saada teada soovitud filtreeritavad andmeväljad.
+ """
chosen_json_values = {}
##Getting API url and json values
diff --git a/modules/telegraf/testing.py b/modules/telegraf/testing.py
deleted file mode 100644
index d049bbf..0000000
--- a/modules/telegraf/testing.py
+++ /dev/null
@@ -1,17 +0,0 @@
-import toml
-
-def modify_input(template, new_pipeline_path, key, value):
- data = toml.load(template)
- pluggin = data["inputs"]["http"][0]
-
- if key in pluggin:
-
- print(f"Before: {key} = {http_input[key]}")
- http_input[key] = value
- print(f"After: {key} = {http_input[key]}")
-
-
- with open(new_pipeline_path, "w") as f:
- toml.dump(data, f)
-
-modify_input("templates/basic_ETL.toml", "test_pipers.toml, "urls", ["stillTesting"])
diff --git a/requirements.txt b/requirements.txt
index c16f892..7ae9633 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -7,4 +7,5 @@ pyfiglet==1.0.2
Pygments==2.19.1
requests==2.32.3
rich==14.0.0
+toml==0.10.2
urllib3==2.3.0