Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
codewc opened this issue May 31, 2021 · 2 comments
Closed

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

codewc opened this issue May 31, 2021 · 2 comments
Labels
enhancement New feature or request scrapy Scrapy related

Comments

@codewc
Copy link

codewc commented May 31, 2021

/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
Copy link
Author

codewc commented May 31, 2021

WX20210531-162412@2x

比如setttings.py这种文件结构,会出现该问题

@tikazyq tikazyq added bug Something isn't working enhancement New feature or request and removed bug Something isn't working labels May 31, 2021
@tikazyq tikazyq added the scrapy Scrapy related label Aug 4, 2021
@ChibahAbdelwahab
Copy link

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

@tikazyq tikazyq closed this as completed Jun 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request scrapy Scrapy related
Projects
None yet
Development

No branches or pull requests

3 participants