forked from LiveCarta/LiveCartaMeta
50 lines
1.3 KiB
Python
50 lines
1.3 KiB
Python
import argparse
|
|
from configs.config import config
|
|
from sources.BaseSource import BaseSource
|
|
|
|
|
|
class Updater:
|
|
def __init__(self):
|
|
parser = argparse.ArgumentParser(description="Source parser.")
|
|
parser.add_argument("--config", help='Update config action', action='store_true')
|
|
parser.add_argument("--source", type=str)
|
|
|
|
self.args = parser.parse_args()
|
|
|
|
def is_source_exists(self, source):
|
|
try:
|
|
config.get_source_by_name(source)
|
|
except ValueError:
|
|
return False
|
|
|
|
return True
|
|
|
|
def parse_source(self, source):
|
|
source_config = config.get_source_by_name(source)
|
|
source_model = BaseSource(**source_config)
|
|
|
|
if not source_model.check_is_update_needed():
|
|
print('Nothing to update')
|
|
return
|
|
else:
|
|
updated = source_model.update_data()
|
|
print('Rows added: ' + str(updated))
|
|
|
|
def update_config(self):
|
|
config.update_sources()
|
|
|
|
def do_action(self):
|
|
if self.args.config:
|
|
self.update_config()
|
|
return
|
|
|
|
if not self.is_source_exists(self.args.source):
|
|
print("This source not exists, list of sources: " + ', '.join(config.get_sources_list()))
|
|
return
|
|
|
|
self.parse_source(self.args.source)
|
|
|
|
|
|
updater = Updater()
|
|
updater.do_action()
|