package.py 755 字节
Newer Older
F
feilong 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
import os
import uuid

from src.main.utils import load_json, dump_json


class Package:
    def __init__(self, root) -> None:
        self.root = root

    def walk(self):
        for base, dirs, files in os.walk(self.root):
            for file_name in files:
                file_full_name = os.path.join(base, file_name)
                _, ext = os.path.splitext(file_name)
                if ext == '.json':
                    pkg = load_json(file_full_name)
                    if pkg.get('type') == 'career':
                        self.visit_package(file_full_name, pkg)

    def visit_package(self, file_full_name, pkg):
F
feilong 已提交
22
        pkg['package_id'] = 'career-'+uuid.uuid4().hex
F
feilong 已提交
23
        dump_json(file_full_name, pkg, exist_ok=True, override=True)