refactor(mapping): try to create mapping for parent tasks

This commit is contained in:
Angelina Tingaeva 2023-11-30 20:47:05 +05:00
parent f6a7724f4e
commit 9f7a57e8aa

View File

@ -2,7 +2,7 @@ import csv
import json import json
import os import os
import sys import sys
import logging # import logging
import requests import requests
@ -44,6 +44,7 @@ def get_assignee_data():
mapping[asana_id] = ya_login mapping[asana_id] = ya_login
return mapping return mapping
assignee = get_assignee_data() assignee = get_assignee_data()
@ -109,7 +110,7 @@ def create_tasks_in_tracker(data):
# 'completedAt': task['completedAt'] # 'completedAt': task['completedAt']
} }
logger.debug('Запрос: %s', json.dumps(payload)) # logger.debug('Запрос: %s', json.dumps(payload))
response = requests.post( response = requests.post(
base_url, base_url,
@ -124,7 +125,30 @@ def create_tasks_in_tracker(data):
'Ошибка при создании задачи в ЯндексТрекер:', 'Ошибка при создании задачи в ЯндексТрекер:',
response.content, 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() # asana_data = get_data_from_asana()
file = open(asana_data_json, "r", encoding="utf8") file = open(asana_data_json, "r", encoding="utf8")