functions.py 915 Bytes
Newer Older
Matteo's avatar
Matteo committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import os
import subprocess
import json
import yaml


def analyze(files_name: str, working_path: str | None = None) -> subprocess.CompletedProcess:
    executable = os.path.abspath("frame_extraction/bin/frame_extraction")

    config = get_file_content("config/config.json", "json")

    # Update configuration file with query parameters
    config["FilesName"] = files_name
    if working_path is not None:
        config["WorkingPath"] = working_path
    with open("config/config.json", "w") as json_file:
        json.dump(config, json_file)

    process = subprocess.run([executable], capture_output=True)
    return process


def get_file_content(file_name: str, format: str) -> dict:

    with open(file_name) as fd:
        if format == "yaml":
            content = yaml.safe_load(fd)
            return content
        elif format == "json":
            content = json.load(fd)
    
        return content