From 65a520f88d0b0a36b1a2b951a387a1fea67bf0de Mon Sep 17 00:00:00 2001 From: Ivan Filippov Date: Thu, 14 Dec 2023 16:11:07 +0500 Subject: [PATCH] launching the parser through the command manager and writing to a file --- .../core/management/commands/fill-db.py | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/adaptive_hockey_federation/core/management/commands/fill-db.py b/adaptive_hockey_federation/core/management/commands/fill-db.py index 12bf3418..fddd1f01 100644 --- a/adaptive_hockey_federation/core/management/commands/fill-db.py +++ b/adaptive_hockey_federation/core/management/commands/fill-db.py @@ -1,9 +1,25 @@ +import os +import subprocess from django.core.management.base import BaseCommand +from adaptive_hockey_federation.settings import BASE_DIR + +RESOURSES_ROOT = os.path.join(BASE_DIR, 'resourses') +PARSER_MAIN = os.path.join(BASE_DIR, 'parser/parser.py') + class Command(BaseCommand): help = "Описание команды" def handle(self, *args, **options): - return 'Я заготовка' + run_parser = subprocess.getoutput( + f'poetry run python {PARSER_MAIN} -r -p {RESOURSES_ROOT}' + ) + with open( + f'{RESOURSES_ROOT}/result.txt', + 'w', + encoding='utf-8', + ) as file: + print(run_parser) + file.write(run_parser)