Merge pull request #11 from bivis/develop

Develop
This commit is contained in:
bivis
2023-02-07 12:08:34 +03:00
committed by GitHub
3 changed files with 15 additions and 11 deletions

View File

@@ -14,7 +14,3 @@ COPY ./ ./
RUN chmod 777 /app/configs/sources.json RUN chmod 777 /app/configs/sources.json
RUN python update.py --config
RUN python update.py --source test

View File

@@ -9,16 +9,18 @@ from configs.configs import CONFIGS
class AppConfig: class AppConfig:
def __init__(self): def __init__(self):
self.config = Dynaconf(settings_files=[ self.refresh()
"/app/configs/main.json",
"/app/configs/sources.json"
])
connect( connect(
db=CONFIGS['db']['name'], db=CONFIGS['db']['name'],
host="mongodb://{host}:27017/{database}".format(host=CONFIGS['db']['host'], database=CONFIGS['db']['name']) host="mongodb://{host}:27017/{database}".format(host=CONFIGS['db']['host'], database=CONFIGS['db']['name'])
) )
def refresh(self):
self.config = Dynaconf(settings_files=[
"/app/configs/main.json",
"/app/configs/sources.json"
])
def get_bulk_insert_limit(self): def get_bulk_insert_limit(self):
if not self.config.bulk_limit: if not self.config.bulk_limit:
return 1 return 1
@@ -40,6 +42,7 @@ class AppConfig:
} }
r = requests.get(CONFIGS['application_credentials']['api_url'] + "sources", headers=headers) r = requests.get(CONFIGS['application_credentials']['api_url'] + "sources", headers=headers)
if r.status_code != 200: if r.status_code != 200:
raise Exception('Bad app response') raise Exception('Bad app response')
new_config = {"sources": {}} new_config = {"sources": {}}
@@ -48,5 +51,7 @@ class AppConfig:
with open("./configs/sources.json", "w") as outfile: with open("./configs/sources.json", "w") as outfile:
outfile.write(json.dumps(new_config)) outfile.write(json.dumps(new_config))
self.refresh()
config = AppConfig() config = AppConfig()

View File

@@ -34,14 +34,17 @@ class Updater:
config.update_sources() config.update_sources()
def do_action(self): def do_action(self):
print("Start Updater");
if self.args.config: if self.args.config:
print("Start Configure")
self.update_config() self.update_config()
return return
if not self.is_source_exists(self.args.source): if not self.is_source_exists(self.args.source):
print("This source not exists, list of sources: " + ', '.join(config.get_sources_list())) print("This source not exists, list of sources: " + ', '.join(config.get_sources_list()))
return return
print("Start source update")
self.parse_source(self.args.source) self.parse_source(self.args.source)