From e1e199c53fa2993f6e47b572338ba5e1c09f249e Mon Sep 17 00:00:00 2001 From: Angelina Tingaeva Date: Mon, 11 Dec 2023 17:05:28 +0500 Subject: [PATCH] refactor(resolved_tasks):add check for getting answer-issue, try to get tasks in response --- resolved_task.py | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/resolved_task.py b/resolved_task.py index e531c6d..b8122ac 100644 --- a/resolved_task.py +++ b/resolved_task.py @@ -1,14 +1,11 @@ -import csv import json import os import sys -import time import requests from logging_config import setup_logging -from urllib.parse import urlencode logger = setup_logging(__name__) @@ -22,16 +19,10 @@ sys.stdout.reconfigure(encoding='utf-8') QUEUE_NAME = 'TESTIMPORT' -# headers = { -# 'Host': 'api.tracker.yandex.net', -# 'Authorization': 'OAuth y0_AgAEA7qkB3KjAArkXwAAAADzMlP9oR1lwMzBS2e94jHzdnII8Laxi7k', -# 'X-Org-ID': '7095769', -# 'Content-Type': 'appication/json', -# } - def close_tasks_in_queue(queue_name): base_url = 'https://api.tracker.yandex.net/v2/issues/_search' + # base_url = 'https://api.tracker.yandex.net/v2/issues/_search?expand=transitions' headers = { 'Host': 'api.tracker.yandex.net', 'Authorization': 'OAuth y0_AgAEA7qkB3KjAArkXwAAAADzMlP9oR1lwMzBS2e94jHzdnII8Laxi7k', @@ -53,11 +44,13 @@ def close_tasks_in_queue(queue_name): ) if response.status_code == 200: - tasks = response.json().get('issues', []) + print('Response is ok, lets close tasks!') + tasks = response.json().get('status', []) for task in tasks: - task_id = task['id'] + task_id = task['issue-id'] close_payload = { - 'status': 'resolved' # Установка статуса "Закрыт" + 'status': 'resolved', # Установка статуса "Закрыт" + # 'comment': 'Задача была создана в тестовом режиме' } close_url = f'https://api.tracker.yandex.net/v2/issues/{task_id}' close_response = requests.patch( @@ -72,5 +65,6 @@ def close_tasks_in_queue(queue_name): else: print(f'Ошибка при получении задач для очереди {queue_name}: {response.content}') + # Вызов функции для закрытия задач в очереди 'TESTIMPORT' close_tasks_in_queue('TESTIMPORT')