From 9f7a57e8aaa8f67f2050040d443500fefcfbe7c7 Mon Sep 17 00:00:00 2001 From: Angelina Tingaeva Date: Thu, 30 Nov 2023 20:47:05 +0500 Subject: [PATCH] refactor(mapping): try to create mapping for parent tasks --- mapping.py | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/mapping.py b/mapping.py index a3068dc..18ce92c 100644 --- a/mapping.py +++ b/mapping.py @@ -2,7 +2,7 @@ import csv import json import os import sys -import logging +# import logging import requests @@ -44,6 +44,7 @@ def get_assignee_data(): mapping[asana_id] = ya_login return mapping + assignee = get_assignee_data() @@ -109,7 +110,7 @@ def create_tasks_in_tracker(data): # 'completedAt': task['completedAt'] } - logger.debug('Запрос: %s', json.dumps(payload)) + # logger.debug('Запрос: %s', json.dumps(payload)) response = requests.post( base_url, @@ -124,7 +125,30 @@ def create_tasks_in_tracker(data): 'Ошибка при создании задачи в ЯндексТрекер:', response.content, ) - logger.debug('Ответ: %s', response.content) + # logger.debug('Ответ: %s', response.content) + + ya_imported_task_response = response.json() + if task.get('parent'): + 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'] + update_parent_task( + base_url, + headers, + ya_imported_task_response['id'], + parent_task_id, + ) + + +def update_parent_task(base_url, headers, task_id, parent_task_id): + """ Обновление данных родительской задачи в ЯндексТрекере""" + + payload = { + 'parent': parent_task_id + } + + update_url = f"{base_url}/{task_id}" + # asana_data = get_data_from_asana() file = open(asana_data_json, "r", encoding="utf8")