2022-08-24 15:55:53 +01:00
|
|
|
from flask import current_app as app
|
|
|
|
|
|
|
|
import json
|
|
|
|
from os.path import isfile
|
|
|
|
from pathlib import Path
|
|
|
|
|
2022-08-31 14:50:47 +01:00
|
|
|
from copy import deepcopy
|
|
|
|
|
2022-08-29 17:09:29 +01:00
|
|
|
def check_file(filename:str) -> bool:
|
2022-08-24 15:55:53 +01:00
|
|
|
data_dir = Path(app.config.get('DATA'))
|
|
|
|
if isfile(f'./{data_dir}/{filename}'): return True
|
|
|
|
return False
|
|
|
|
|
2022-08-29 17:09:29 +01:00
|
|
|
def load(filename:str) -> dict:
|
2022-08-24 15:55:53 +01:00
|
|
|
data_dir = Path(app.config.get('DATA'))
|
2022-08-31 14:50:47 +01:00
|
|
|
with open(f'./{data_dir}/{filename}') as file: return json.load(file)
|
|
|
|
|
|
|
|
def declutter_results(raw_results:dict) -> dict:
|
|
|
|
data = deepcopy(raw_results)
|
|
|
|
playbook_lists = []
|
|
|
|
for item in data['playbooks']:
|
|
|
|
playbook_lists.append(list(item.keys())[0])
|
|
|
|
data['playbooks'] = playbook_lists
|
|
|
|
return data
|