From ab72d01c5b044d89f2aeebd9fbc11b1adb1b5897 Mon Sep 17 00:00:00 2001 From: Noretsa Date: Sun, 21 Jun 2020 15:48:22 +0300 Subject: [PATCH] =?UTF-8?q?=D0=9D=D0=B0=D1=81=D1=82=D1=80=D0=BE=D0=B5?= =?UTF-8?q?=D0=BD=D0=B0=20=D0=BF=D0=BE=D0=B2=D1=82=D0=BE=D1=80=D0=BD=D0=B0?= =?UTF-8?q?=D1=8F=20=D0=BE=D1=82=D0=BF=D1=80=D0=B0=D0=B2=D0=BA=D0=B0=20?= =?UTF-8?q?=D1=84=D0=BE=D1=82=D0=BE=20=D0=BF=D1=80=D0=B8=20=D0=BD=D0=B5?= =?UTF-8?q?=D1=83=D0=B4=D0=B0=D1=87=D0=BD=D0=BE=D0=B9=20=D0=BE=D1=82=D0=BF?= =?UTF-8?q?=D1=80=D0=B0=D0=B2=D0=BA=D0=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- knd_bot.py | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) 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())})