refactor(resolved_tasks):add check for getting answer-issue, try to get tasks in response

This commit is contained in:
Angelina Tingaeva 2023-12-11 17:05:28 +05:00
parent 2edd6fd3df
commit e1e199c53f

View File

@ -1,14 +1,11 @@
import csv
import json import json
import os import os
import sys import sys
import time
import requests import requests
from logging_config import setup_logging from logging_config import setup_logging
from urllib.parse import urlencode
logger = setup_logging(__name__) logger = setup_logging(__name__)
@ -22,16 +19,10 @@ sys.stdout.reconfigure(encoding='utf-8')
QUEUE_NAME = 'TESTIMPORT' 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): 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'
# base_url = 'https://api.tracker.yandex.net/v2/issues/_search?expand=transitions'
headers = { headers = {
'Host': 'api.tracker.yandex.net', 'Host': 'api.tracker.yandex.net',
'Authorization': 'OAuth y0_AgAEA7qkB3KjAArkXwAAAADzMlP9oR1lwMzBS2e94jHzdnII8Laxi7k', 'Authorization': 'OAuth y0_AgAEA7qkB3KjAArkXwAAAADzMlP9oR1lwMzBS2e94jHzdnII8Laxi7k',
@ -53,11 +44,13 @@ def close_tasks_in_queue(queue_name):
) )
if response.status_code == 200: 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: for task in tasks:
task_id = task['id'] task_id = task['issue-id']
close_payload = { close_payload = {
'status': 'resolved' # Установка статуса "Закрыт" 'status': 'resolved', # Установка статуса "Закрыт"
# 'comment': 'Задача была создана в тестовом режиме'
} }
close_url = f'https://api.tracker.yandex.net/v2/issues/{task_id}' close_url = f'https://api.tracker.yandex.net/v2/issues/{task_id}'
close_response = requests.patch( close_response = requests.patch(
@ -72,5 +65,6 @@ def close_tasks_in_queue(queue_name):
else: else:
print(f'Ошибка при получении задач для очереди {queue_name}: {response.content}') print(f'Ошибка при получении задач для очереди {queue_name}: {response.content}')
# Вызов функции для закрытия задач в очереди 'TESTIMPORT' # Вызов функции для закрытия задач в очереди 'TESTIMPORT'
close_tasks_in_queue('TESTIMPORT') close_tasks_in_queue('TESTIMPORT')