Created
August 26, 2021 08:20
-
-
Save twinsant/44cfba7ac87d95aa0fe26f0d0fa4d9b0 to your computer and use it in GitHub Desktop.
crawlab core hack
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @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('__')]: | |
| v = getattr(settings, key) | |
| # Hack: need check value type to avoid "TypeError: Object of type 'module' is not JSON serializable" | |
| from types import ModuleType | |
| if isinstance(v, ModuleType): | |
| continue | |
| # End Hack | |
| data.append({ | |
| 'key': key, | |
| 'value': v, | |
| }) | |
| print(json.dumps(data)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment