Untitled

mail@pastecode.io avatar
unknown
python
a month ago
1.3 kB
1
Indexable
Never
from glob import glob
import zipfile
import json
from rich.progress import track


files = glob("./files/*/*zip")


top_key_set = set()

keys_list = {}

for zip_file in track(files):
    with zipfile.ZipFile(files[0], "r") as zip_ref:
        for filename in zip_ref.namelist():
            if filename.endswith(".json"):
                with zip_ref.open(filename) as file:
                    data = json.load(file)
                    for key, value in data.items():
                        if isinstance(value, dict):
                            if not keys_list.get(key):
                                keys_list[key] = set(value.keys())
                            else:
                                # print(keys_list[key])
                                keys_list[key].update(set(value.keys()))
                        elif isinstance(value, list):
                            for val in value:
                                if isinstance(val, dict):
                                    if not keys_list.get(key):
                                        keys_list[key] = set(val.keys())
                                    else:
                                        keys_list[key].update(set(val.keys()))

                        else:
                            keys_list[key] = ""
Leave a Comment