Commit b46ed74629912baca5c77313f296407522b5c16b
Committed by
Gust
1 parent
c033b7ea
Exists in
master
and in
39 other branches
Removed eval from import_proxy_data
Showing
2 changed files
with
16 additions
and
11 deletions
Show diff stats
colab/proxy/proxybase/management/commands/import_proxy_data.py
1 | 1 | #!/usr/bin/env python |
2 | 2 | |
3 | -import colab | |
3 | +import importlib | |
4 | + | |
4 | 5 | from django.core.management.base import BaseCommand |
5 | -from colab.super_archives.models import Message | |
6 | 6 | from django.conf import settings |
7 | -modules = [ i for i in settings.INSTALLED_APPS if i.startswith("colab.proxy.") ] | |
8 | -for module in modules: | |
9 | - module += ".data_api" | |
10 | - __import__(module, locals(), globals()) | |
7 | + | |
8 | +from colab.proxy.proxybase.proxy_data_api import ProxyDataAPI | |
9 | + | |
11 | 10 | |
12 | 11 | class Command(BaseCommand): |
13 | 12 | help = "Import proxy data into colab database" |
... | ... | @@ -15,7 +14,13 @@ class Command(BaseCommand): |
15 | 14 | def handle(self, *args, **kwargs): |
16 | 15 | print "Executing extraction command..." |
17 | 16 | |
18 | - for module in modules: | |
19 | - extractionClassname = module + ".data_api." + module.split('.')[-1].title() + "DataAPI" | |
20 | - api = eval(extractionClassname)() | |
21 | - api.fetchData() | |
17 | + for module_name in settings.PROXIED_APPS.keys(): | |
18 | + module_path = 'colab.proxy.{}.data_api'.format(module_name) | |
19 | + module = importlib.import_module(module_path) | |
20 | + | |
21 | + for module_item_name in dir(module): | |
22 | + module_item = getattr(module, module_item_name) | |
23 | + if issubclass(module_item, ProxyDataAPI): | |
24 | + if module_item != ProxyDataAPI: | |
25 | + api = module_item() | |
26 | + api.fetchData() | ... | ... |
colab/settings.py
... | ... | @@ -320,7 +320,7 @@ if FEEDZILLA_ENABLED: |
320 | 320 | 'common', |
321 | 321 | ) |
322 | 322 | |
323 | -proxied_apps = locals().get('PROXIED_APPS') or {} | |
323 | +PROXIED_APPS = locals().get('PROXIED_APPS') or {} | |
324 | 324 | BROWSERID_ENABLED = locals().get('BROWSERID_ENABLED') or False |
325 | 325 | |
326 | 326 | for app_label in proxied_apps.keys(): | ... | ... |