diff --git a/knd_bot.py b/knd_bot.py index 9596611..a06665a 100644 --- a/knd_bot.py +++ b/knd_bot.py @@ -32,9 +32,12 @@ def send_image(session, headers, url, photo): # print(files) img = session.post('https://knd.mosreg.ru//api/v1/executions/'+str(url)+'/images', headers=headers, files=files) if img.status_code == 200: + print(f"Фото {photo} успешно отправлено") return img.json() else: - print(f"Не удалось загрузить фото на сервер по заданию {url}, статус ошибки {img.status_code}! Завершите его вручную!") + print(f"Не удалось загрузить фото на сервер по заданию {url}, статус ошибки {img.status_code}! Повторная попытка!") + second_img = send_image(session, headers, url, photo) + return second_img def complete_task(session, headers, task, address): @@ -67,7 +70,13 @@ def complete_task(session, headers, task, address): for chain in data: for item in chain['questions']: if len(data) == len(photos): - img = send_image(session, headers, task['id'], photos.pop(0)) + photo_from_photos = photos.pop(0) + img = send_image(session, headers, task['id'], photo_from_photos)#photos.pop(0)) + count_send_photo = 0 + while img['id'] is None: + count_send_photo += 1 + print("Попытка № " + str(count_send_photo) + "отправить фото" + str(photo_from_photos)) + img = send_image(session, headers, task['id'], photo_from_photos)#photos.pop(0)) first = {"id": 18850, "answer": [img['id']], 'answer_status': None, 'start_time': int(time.time())} time.sleep(2) first.update({'end_time': int(time.time())}) @@ -77,7 +86,14 @@ def complete_task(session, headers, task, address): item['question_components'].append(first) item['question_components'].append(second) else: - img = send_image(session, headers, task['id'], photos.pop(0)) + #img = send_image(session, headers, task['id'], photos.pop(0)) + photo_from_photos = photos.pop(0) + img = send_image(session, headers, task['id'], photo_from_photos)#photos.pop(0)) + count_send_photo = 0 + while img['id'] is None: + count_send_photo += 1 + print("Попытка № " + str(count_send_photo) + " отправить фото" + str(photo_from_photos)) + img = send_image(session, headers, task['id'], photo_from_photos)#photos.pop(0)) first = {"id": 18856, "answer": 77, 'answer_status': None, 'start_time': int(time.time())} time.sleep(2) first.update({'end_time': int(time.time())})