78 lines
2.4 KiB
Python
78 lines
2.4 KiB
Python
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')
|