crawlab icon indicating copy to clipboard operation
crawlab copied to clipboard

crawlab/core/client.py获取settings可优化判断

Open codewc opened this issue 4 years ago • 2 comments

/usr/local/lib/python3.8/dist-packages/crawlab/core/client.py文件190行

@staticmethod
def settings(directory=None):
    if directory is None:
        directory = os.path.abspath(os.curdir)
    os.chdir(directory)

    cp = get_scrapy_cfg()

    settings_mod_name = cp.get('settings', 'default')

    sys.path.insert(0, directory)
    settings = importlib.import_module(settings_mod_name)

    data = []
    for key in [key for key in dir(settings) if not key.startswith('__')]:

        value = getattr(settings, key)
        # `建议修改这里的取值,否则后面json.dumps(data)会报错,比如value是一个模块变量的话`
        value = value if isinstance(value, (str, int, bool, dict, tuple)) else str(value)
        data.append({
            'key': key,
            'value': value,
        })

    print(json.dumps(data))

codewc avatar May 31 '21 08:05 codewc

WX20210531-162412@2x 比如setttings.py这种文件结构,会出现该问题

codewc avatar May 31 '21 08:05 codewc

I'm having the same issue, will this be updated soon ?

ChibahAbdelwahab avatar Nov 19 '21 11:11 ChibahAbdelwahab