Commit 19615e857696a9ab938e0efed011ef69f79192d2
Committed by
Gust
1 parent
06c11d47
Exists in
master
and in
39 other branches
Removed eval from import_proxy_data
Showing
1 changed file
with
15 additions
and
10 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() | ... | ... |