From 528e76f3eea6f2ccefe41637ec72df711b589b1b Mon Sep 17 00:00:00 2001 From: Angelina Tingaeva Date: Tue, 5 Dec 2023 02:08:07 +0500 Subject: [PATCH] refactor(mapping): refactor updating data and create messages about updating yandex tracker data with parent task --- logging_config.py | 3 ++- mapping.py | 15 ++++++++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/logging_config.py b/logging_config.py index 722b295..9ad6fba 100644 --- a/logging_config.py +++ b/logging_config.py @@ -17,7 +17,8 @@ def setup_logging(name): file_handler = logging.FileHandler( filename=f"{name}.log", mode='w', - encoding='utf-8' + encoding='utf-8', + delay=True ) file_handler.setLevel(logging.DEBUG) diff --git a/mapping.py b/mapping.py index 2958d74..301e374 100644 --- a/mapping.py +++ b/mapping.py @@ -131,6 +131,9 @@ def create_tasks_in_tracker(data): parent_task_gid = task['parent']['gid'] if parent_task_gid in ya_imported_task_response: parent_task_id = ya_imported_task_response[parent_task_gid]['id'] + logger.debag( + f'В задаче {task['summary']} есть связка "parent"' + ) update_parent_task( base_url, headers, @@ -145,9 +148,19 @@ def update_parent_task(base_url, headers, task_id, parent_task_id): payload = { 'parent': parent_task_id } - update_url = f"{base_url}/{task_id}" + try: + response = requests.post(update_url, headers=headers, data=payload) + + if response.status_code == 200: + print('Данные успешно обновлены с добавлением нового элемента.') + else: + print('Ошибка при обновлении данных.') + + except requests.exceptions.RequestException as error: + print('Произошла ошибка при обновлении данных:', error) + # asana_data = get_data_from_asana() file = open(asana_data_json, "r", encoding="utf8")