From f552c08b33cfb0cf7a9706db55425c97d8f94c08 Mon Sep 17 00:00:00 2001 From: Angelina Tingaeva Date: Sun, 10 Dec 2023 21:15:45 +0500 Subject: [PATCH] =?UTF-8?q?=D0=B0=D1=83=D1=84=D0=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- resolved_task.py | 77 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 resolved_task.py diff --git a/resolved_task.py b/resolved_task.py new file mode 100644 index 0000000..488c783 --- /dev/null +++ b/resolved_task.py @@ -0,0 +1,77 @@ +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__) + +base_dir = os.path.dirname(os.path.realpath(__file__)) +asana_data_json = os.path.join(base_dir, './data/data_asana.json') +users_data = os.path.join(base_dir, './data/users.mapping.asana2ya.csv') + +sys.stdin.reconfigure(encoding='utf-8') +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' + headers = { + 'Host': 'api.tracker.yandex.net', + 'Authorization': 'OAuth y0_AgAEA7qkB3KjAArkXwAAAADzMlP9oR1lwMzBS2e94jHzdnII8Laxi7k', + 'X-Org-ID': '7095769', + 'Content-Type': 'application/json', + } + + payload = { + "filter": { + "queue": queue_name, + "status": "open" # Фильтр для открытых задач в указанной очереди + } + } + + response = requests.post( + base_url, + headers=headers, + data=json.dumps(payload) + ) + + if response.status_code == 200: + tasks = response.json().get('issues', []) + for task in tasks: + task_id = task['id'] + close_payload = { + 'status': 'resolved' # Установка статуса "Закрыт" + } + close_url = f'https://api.tracker.yandex.net/v2/issues/{task_id}' + close_response = requests.patch( + close_url, + headers=headers, + data=json.dumps(close_payload) + ) + if close_response.status_code == 200: + print(f'Задача {task_id} закрыта успешно') + else: + print(f'Ошибка при закрытии задачи {task_id}: {close_response.content}') + else: + print(f'Ошибка при получении задач для очереди {queue_name}: {response.content}') + + +# Вызов функции для закрытия задач в очереди 'TESTIMPORT' +close_tasks_in_queue('TESTIMPORT')