Исправление ошибки
было добавлено задание на сервере
This commit is contained in:
parent
b7c4bca9c4
commit
151a915911
122
des.py
122
des.py
@ -23,107 +23,30 @@ def send_image(session, headers, url, photo):
|
|||||||
'image': (photo[-5:], open(photo, 'rb')),
|
'image': (photo[-5:], open(photo, 'rb')),
|
||||||
}
|
}
|
||||||
# print(files)
|
# print(files)
|
||||||
img = session.post('https://knd.mosreg.ru//api/v1/executions/'+str(url)+'/images', headers=headers, files=files)
|
img = session.post('https://knd.mosreg.ru//api/v1/executions/'+str(url) +
|
||||||
|
'/images', headers=headers, files=files)
|
||||||
if img.status_code == 200:
|
if img.status_code == 200:
|
||||||
print(f"Фото {photo} успешно отправлено")
|
print(f"Фото {photo} успешно отправлено")
|
||||||
return img.json()
|
return img.json()
|
||||||
else:
|
else:
|
||||||
print(f"Не удалось загрузить фото на сервер по заданию {url}, статус ошибки {img.status_code}! Повторная попытка!")
|
print(f"Не удалось загрузить фото на сервер по заданию {url}, \
|
||||||
|
статус ошибки {img.status_code}! Повторная попытка!")
|
||||||
second_img = send_image(session, headers, url, photo)
|
second_img = send_image(session, headers, url, photo)
|
||||||
return second_img
|
return second_img
|
||||||
|
|
||||||
|
|
||||||
# def complete_task(session, headers, task, address):
|
|
||||||
# photos = get_photo(address, headers['uid'])
|
|
||||||
# if len(photos) > 0:
|
|
||||||
# photos.sort()
|
|
||||||
# print(task['id'])
|
|
||||||
# id_task = task['id']
|
|
||||||
# questions = get_questions(id_task, session, headers)
|
|
||||||
# data = []
|
|
||||||
# for answers in questions:
|
|
||||||
# answer_chain = {
|
|
||||||
# 'id': answers['id'],
|
|
||||||
# 'questions': [] # answers['questions']
|
|
||||||
# }
|
|
||||||
# if answer_chain['id'] == 6146: # Цепочка без ответов
|
|
||||||
# continue
|
|
||||||
# for components in answers['questions']:
|
|
||||||
# comp = []
|
|
||||||
# q_c = {
|
|
||||||
# 'id': components['id'],
|
|
||||||
# 'question_components': []
|
|
||||||
# }
|
|
||||||
# if q_c['id'] == 6560: # Вопрос без ответа
|
|
||||||
# continue
|
|
||||||
# comp.append(q_c)
|
|
||||||
# answer_chain.update({'questions': comp})
|
|
||||||
# data.append(answer_chain)
|
|
||||||
# if len(data) == len(photos):
|
|
||||||
# for chain in data:
|
|
||||||
# for item in chain['questions']:
|
|
||||||
# if len(data) == len(photos):
|
|
||||||
# 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())})
|
|
||||||
# second = {"id": 18851, "answer": {"location": task['coord']}, 'answer_status': None, 'start_time': int(time.time())}
|
|
||||||
# time.sleep(2)
|
|
||||||
# second.update({'end_time': int(time.time())})
|
|
||||||
# item['question_components'].append(first)
|
|
||||||
# item['question_components'].append(second)
|
|
||||||
# else:
|
|
||||||
# # 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())})
|
|
||||||
# second = {"id": 18857, "answer": [img['id']], 'answer_status': None, 'start_time': int(time.time())}
|
|
||||||
# time.sleep(2)
|
|
||||||
# second.update({'end_time': int(time.time())})
|
|
||||||
# item['question_components'].append(first)
|
|
||||||
# item['question_components'].append(second)
|
|
||||||
# ans = {"question_chains": data}
|
|
||||||
# # print(ans)
|
|
||||||
# session_t = session
|
|
||||||
# session_t.headers.update(
|
|
||||||
# {
|
|
||||||
# 'referer': 'https://knd.mosreg.ru/executions'+str(task['id'])+'/solve',
|
|
||||||
# 'x-platform': 'wb',
|
|
||||||
# 'accept': '*/*'
|
|
||||||
# }
|
|
||||||
# )
|
|
||||||
# complete = session_t.post('https://knd.mosreg.ru//api/v1/executions/'+str(task['id'])+'/answers', headers=headers, json=ans)
|
|
||||||
# if complete.status_code == 200:
|
|
||||||
# print(f'Задание по адресу {address} выполнено успешно!')
|
|
||||||
# else:
|
|
||||||
# print(f'Задание по адресу {address} не выполненно! Статус ошибки {complete.status_code}')
|
|
||||||
# else:
|
|
||||||
# print(f"Несоответствие количества вопросов и количества фотографий по адресу: {address}")
|
|
||||||
# # send_execution(task,session, headers)
|
|
||||||
|
|
||||||
|
|
||||||
def get_photo(address, email):
|
def get_photo(address, email):
|
||||||
photos = []
|
photos = []
|
||||||
month = datetime.datetime.now().month
|
month = datetime.datetime.now().month
|
||||||
main_path = os.path.join(os.path.abspath('.'), 'data', email, str(month), address)
|
main_path = os.path.join(os.path.abspath('.'), 'data', email, str(month),
|
||||||
|
address)
|
||||||
if not os.path.exists(main_path):
|
if not os.path.exists(main_path):
|
||||||
return photos
|
return photos
|
||||||
else:
|
else:
|
||||||
for images in os.listdir(main_path):
|
for images in os.listdir(main_path):
|
||||||
if images.endswith(".jpg") or images.endswith(".jpeg") or images.endswith(".JPG"):
|
if (images.endswith(".jpg") or
|
||||||
|
images.endswith(".jpeg") or
|
||||||
|
images.endswith(".JPG")):
|
||||||
photos.append(main_path + '/' + images)
|
photos.append(main_path + '/' + images)
|
||||||
return photos
|
return photos
|
||||||
|
|
||||||
@ -134,23 +57,15 @@ def get_addresses(email):
|
|||||||
main_path = os.path.join(os.path.abspath('.'), 'data')
|
main_path = os.path.join(os.path.abspath('.'), 'data')
|
||||||
path = os.walk(os.path.join(main_path, email, str(month)))
|
path = os.walk(os.path.join(main_path, email, str(month)))
|
||||||
if not os.path.exists(os.path.join(main_path, email, str(month))):
|
if not os.path.exists(os.path.join(main_path, email, str(month))):
|
||||||
return f"Не найдена папка с месяцем у пользователя {email}! Проверьте структуру каталога!"
|
return f"Не найдена папка с месяцем у пользователя {email}! Проверьте \
|
||||||
|
структуру каталога!"
|
||||||
for d, dirs, files in path:
|
for d, dirs, files in path:
|
||||||
addresses.append(dirs)
|
addresses.append(dirs)
|
||||||
if len(addresses[0]) > 0:
|
if len(addresses[0]) > 0:
|
||||||
return addresses[0]
|
return addresses[0]
|
||||||
else:
|
else:
|
||||||
return f"Ни одного адреса для пользователя {email} не найдено! Добавьте фото и запустите программу снова!"
|
return f"Ни одного адреса для пользователя {email} не найдено! \
|
||||||
|
Добавьте фото и запустите программу снова!"
|
||||||
|
|
||||||
# def assign_task(session, headers, task, address):
|
|
||||||
# url = 'https://knd.mosreg.ru//api/v1/executions/'+str(task['id'])+'/assign'
|
|
||||||
# task_assign = session.put(url, headers=headers)
|
|
||||||
# if task_assign.status_code == 200:
|
|
||||||
# print(f'Получили задани по адресу: {address}')
|
|
||||||
# complete_task(session, headers, task, address)
|
|
||||||
# else:
|
|
||||||
# print(f"Не смогли получить задание {address} {task['id']}!")
|
|
||||||
|
|
||||||
|
|
||||||
def get_task(session, headers):
|
def get_task(session, headers):
|
||||||
@ -191,8 +106,11 @@ def get_task(session, headers):
|
|||||||
json_tasks = tasks.json()
|
json_tasks = tasks.json()
|
||||||
# get_t = False
|
# get_t = False
|
||||||
# Если есть доступное задание с таким адресом
|
# Если есть доступное задание с таким адресом
|
||||||
exec_assigned = json_tasks['executions_assigned'] # Уже полученные задания
|
#
|
||||||
exec_available = json_tasks['executions_available'] # Еще не принятые задания
|
# Уже полученные задания
|
||||||
|
exec_assigned = json_tasks['executions_assigned']
|
||||||
|
# Еще не принятые задания
|
||||||
|
exec_available = json_tasks['executions_available']
|
||||||
# print(address)
|
# print(address)
|
||||||
if len(exec_available) > 0:
|
if len(exec_available) > 0:
|
||||||
for n in exec_available:
|
for n in exec_available:
|
||||||
@ -201,9 +119,9 @@ def get_task(session, headers):
|
|||||||
for execution in enterances:
|
for execution in enterances:
|
||||||
address_from_tasks = execution['dimensions'][0].get('entity_value_name')
|
address_from_tasks = execution['dimensions'][0].get('entity_value_name')
|
||||||
name_from_tasks = execution['name']
|
name_from_tasks = execution['name']
|
||||||
|
if name_from_tasks == desinfection:
|
||||||
enterance = execution['dimensions'][2].get('entity_value_name')
|
enterance = execution['dimensions'][2].get('entity_value_name')
|
||||||
if address_from_tasks == 'Клин г, ' + addr.replace("_", "/")[:-4] and \
|
if address_from_tasks == 'Клин г, ' + addr.replace("_", "/")[:-4] and enterance[-1] == address[-2]:
|
||||||
enterance[-1] == address[-2]:
|
|
||||||
print('\n')
|
print('\n')
|
||||||
print(name_from_tasks)
|
print(name_from_tasks)
|
||||||
print('\n')
|
print('\n')
|
||||||
|
|||||||
@ -201,9 +201,9 @@ def get_task(session, headers):
|
|||||||
for execution in enterances:
|
for execution in enterances:
|
||||||
address_from_tasks = execution['dimensions'][0].get('entity_value_name')
|
address_from_tasks = execution['dimensions'][0].get('entity_value_name')
|
||||||
name_from_tasks = execution['name']
|
name_from_tasks = execution['name']
|
||||||
|
if name_from_tasks == desinfection:
|
||||||
enterance = execution['dimensions'][2].get('entity_value_name')
|
enterance = execution['dimensions'][2].get('entity_value_name')
|
||||||
if address_from_tasks == 'Клин г, ' + addr.replace("_", "/")[:-4] and \
|
if address_from_tasks == 'Клин г, ' + addr.replace("_", "/")[:-4] and enterance[-1] == address[-2]:
|
||||||
enterance[-1] == address[-2]:
|
|
||||||
print('\n')
|
print('\n')
|
||||||
print(name_from_tasks)
|
print(name_from_tasks)
|
||||||
print('\n')
|
print('\n')
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user