Skip to content

Instantly share code, notes, and snippets.

@twinsant
Created August 26, 2021 08:20
Show Gist options
  • Select an option

  • Save twinsant/44cfba7ac87d95aa0fe26f0d0fa4d9b0 to your computer and use it in GitHub Desktop.

Select an option

Save twinsant/44cfba7ac87d95aa0fe26f0d0fa4d9b0 to your computer and use it in GitHub Desktop.
crawlab core hack
@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