forked from LiveCarta/LiveCartaMeta
first commit
This commit is contained in:
49
update.py
Normal file
49
update.py
Normal file
@@ -0,0 +1,49 @@
|
||||
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, help='List of sources: ' + ', '.join(config.get_sources_list()))
|
||||
|
||||
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()
|
||||
Reference in New Issue
Block a user