2023-11-21 15:54:48 +05:00
|
|
|
import json
|
|
|
|
|
|
|
|
import requests
|
|
|
|
from yandex_tracker_client import TrackerClient
|
|
|
|
|
|
|
|
client = TrackerClient(
|
2023-11-22 11:51:22 +05:00
|
|
|
token='YANDEX_TRACKER_TOKEN',
|
|
|
|
org_id='ORG_ID'
|
2023-11-21 15:54:48 +05:00
|
|
|
)
|
|
|
|
|
|
|
|
|
2023-11-22 11:51:22 +05:00
|
|
|
YANDEX_TRACKER_TOKEN = 'y0_AgAEA7qkfTFqAArTqQAAAADyduv806rRKh8MS6GOg01ZdwPE-F4ZHuQ'
|
2023-11-21 15:54:48 +05:00
|
|
|
ORG_ID = '35d164dcf81e48f2b6a532f4badddd33'
|
|
|
|
|
|
|
|
|
2023-11-22 11:51:22 +05:00
|
|
|
asana_data_json = './data/data_asana.json'
|
2023-11-21 15:54:48 +05:00
|
|
|
|
2023-11-22 11:51:22 +05:00
|
|
|
|
|
|
|
# ниже функция для случаев, когда не будет готового файла для импорта
|
|
|
|
# def get_data_from_asana():
|
|
|
|
# """ Получение данных из Asana """
|
|
|
|
|
|
|
|
# headers = {
|
|
|
|
# 'Authorization': 'ASANA_TOKEN',
|
|
|
|
# }
|
|
|
|
# response = requests.get('https://api.asana.com/projects/PROJECT_ID/tasks', headers=headers)
|
|
|
|
# data = response.json()
|
|
|
|
# return data
|
|
|
|
|
|
|
|
|
|
|
|
def transform_data(data):
|
2023-11-22 12:13:13 +05:00
|
|
|
""" Преобразование данных из Asana в ЯндексТрекер в совместимом формате """
|
2023-11-22 11:51:22 +05:00
|
|
|
|
|
|
|
transformed_data = []
|
|
|
|
for task in data:
|
|
|
|
transformed_task = {
|
|
|
|
'summary': task['name'],
|
|
|
|
'description': task['notes'],
|
|
|
|
'createdAt': task['created_at'],
|
|
|
|
'deadline': task['due_on'],
|
|
|
|
'assignee': task['assignee'],
|
|
|
|
'milestone': task['section'],
|
|
|
|
# 'memberships': task['memberships'],
|
|
|
|
# 'parent': task[''],
|
|
|
|
'status': task['completed'],
|
|
|
|
}
|
|
|
|
transformed_data.append(transformed_task)
|
|
|
|
return transformed_data
|
|
|
|
|
|
|
|
|
|
|
|
def create_tasks_in_tracker(data):
|
2023-11-22 12:13:13 +05:00
|
|
|
""" Создание задач в ЯндексТрекер """
|
2023-11-22 11:51:22 +05:00
|
|
|
|
|
|
|
base_url = 'https://api.tracker.yandex.net/v2/issues'
|
|
|
|
headers = {
|
|
|
|
'Authorization': 'YANDEX_TRACKER_TOKEN',
|
|
|
|
'Content-Type': 'asana_data_json',
|
2023-11-21 15:54:48 +05:00
|
|
|
}
|
2023-11-22 11:51:22 +05:00
|
|
|
for task in data:
|
|
|
|
payload = {
|
|
|
|
'summary': task['summary'],
|
|
|
|
'description': task['description'],
|
|
|
|
'createdAt': task['createdAt'],
|
|
|
|
'deadline': task['deadline'],
|
|
|
|
'assignee': task['assignee'],
|
|
|
|
'milestone': task['milestone'],
|
|
|
|
# 'memberships': task['memberships'],
|
|
|
|
# 'parent': task['parent'],
|
|
|
|
'status': task['status'],
|
|
|
|
}
|
|
|
|
response = requests.post(
|
|
|
|
base_url,
|
|
|
|
headers=headers,
|
|
|
|
data=json.dumps(payload),
|
|
|
|
)
|
|
|
|
if response.status_code == 201:
|
2023-11-22 12:13:13 +05:00
|
|
|
print('Задача успешно создана в ЯндексТрекер')
|
2023-11-22 11:51:22 +05:00
|
|
|
else:
|
|
|
|
print(
|
2023-11-22 12:13:13 +05:00
|
|
|
'Ошибка при создании задачи в ЯндексТрекер:',
|
2023-11-22 11:51:22 +05:00
|
|
|
response.content,
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
def main():
|
|
|
|
""" Основная функция для переноса данных """
|
|
|
|
# asana_data = get_data_from_asana()
|
2023-11-22 12:13:13 +05:00
|
|
|
with open('asana_data_json', 'r') as file:
|
|
|
|
asana_data = json.load(file)
|
|
|
|
# return asana_data
|
2023-11-22 11:51:22 +05:00
|
|
|
yandex_tracker_data = transform_data(asana_data)
|
|
|
|
create_tasks_in_tracker(yandex_tracker_data)
|
2023-11-21 15:54:48 +05:00
|
|
|
|
|
|
|
|
2023-11-22 11:51:22 +05:00
|
|
|
# Запуск основной функции
|
|
|
|
main()
|