Все работает, ждем тесты
This commit is contained in:
parent
d5f72de57e
commit
9e11dc7d26
BIN
data/.DS_Store
vendored
BIN
data/.DS_Store
vendored
Binary file not shown.
BIN
data/5020051404_11@check.mo/.DS_Store
vendored
Normal file
BIN
data/5020051404_11@check.mo/.DS_Store
vendored
Normal file
Binary file not shown.
BIN
data/5020051404_11@check.mo/6/.DS_Store
vendored
Normal file
BIN
data/5020051404_11@check.mo/6/.DS_Store
vendored
Normal file
Binary file not shown.
BIN
data/5020051404_11@check.mo/6/Некрасино д, 18, 1п/,.textClipping
Normal file
BIN
data/5020051404_11@check.mo/6/Некрасино д, 18, 1п/,.textClipping
Normal file
Binary file not shown.
1
data/5020051404_11@check.mo/pass.txt
Normal file
1
data/5020051404_11@check.mo/pass.txt
Normal file
@ -0,0 +1 @@
|
||||
kn8746
|
||||
BIN
data/byshkin66@bk.ru/.DS_Store
vendored
Normal file
BIN
data/byshkin66@bk.ru/.DS_Store
vendored
Normal file
Binary file not shown.
BIN
data/byshkin66@bk.ru/6/.DS_Store
vendored
Normal file
BIN
data/byshkin66@bk.ru/6/.DS_Store
vendored
Normal file
Binary file not shown.
1
data/byshkin66@bk.ru/pass.txt
Normal file
1
data/byshkin66@bk.ru/pass.txt
Normal file
@ -0,0 +1 @@
|
||||
kn2645
|
||||
BIN
data/domreshetnikovo@gmail.com/.DS_Store
vendored
BIN
data/domreshetnikovo@gmail.com/.DS_Store
vendored
Binary file not shown.
BIN
data/domreshetnikovo@gmail.com/6/.DS_Store
vendored
BIN
data/domreshetnikovo@gmail.com/6/.DS_Store
vendored
Binary file not shown.
BIN
data/osa212@mail.ru/.DS_Store
vendored
BIN
data/osa212@mail.ru/.DS_Store
vendored
Binary file not shown.
BIN
data/osa212@mail.ru/6/.DS_Store
vendored
BIN
data/osa212@mail.ru/6/.DS_Store
vendored
Binary file not shown.
BIN
data/osa212@mail.ru/6/2-я Спартаковская ул, 2, 2п/.DS_Store
vendored
Normal file
BIN
data/osa212@mail.ru/6/2-я Спартаковская ул, 2, 2п/.DS_Store
vendored
Normal file
Binary file not shown.
146
knd_bot.py
146
knd_bot.py
@ -29,16 +29,21 @@ def send_image(session, headers, url, photo):
|
||||
files = {
|
||||
'image': (photo[-5:], open(photo, 'rb')),
|
||||
}
|
||||
print(photo)
|
||||
# print(files)
|
||||
img = session.post('https://knd.mosreg.ru//api/v1/executions/'+str(url)+'/images', headers=headers, files=files)
|
||||
return img.json()
|
||||
if img.status_code == 200:
|
||||
return img.json()
|
||||
else:
|
||||
print(f"Не удалось загрузить фото на сервер по заданию {url}, статус ошибки {img.status_code}! Завершите его вручную!")
|
||||
|
||||
|
||||
def complete_task(session, headers, task, address):
|
||||
photos = get_photo(address, headers['uid'])
|
||||
if len(photos) > 0:
|
||||
photos.sort()
|
||||
questions = get_questions(task['id'], session, headers)
|
||||
print(task['id'])
|
||||
id_task = task['id']
|
||||
questions = get_questions(id_task, session, headers)
|
||||
data = []
|
||||
for answers in questions:
|
||||
answer_chain = {
|
||||
@ -63,19 +68,39 @@ def complete_task(session, headers, task, address):
|
||||
for item in chain['questions']:
|
||||
if len(data) == len(photos):
|
||||
img = send_image(session, headers, task['id'], photos.pop(0))
|
||||
first = {"id": 18850, "answer": [img['id']], 'start_time': int(time.time())}
|
||||
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']}}
|
||||
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))
|
||||
first = {"id": 18856, "answer": 77}
|
||||
second = {"id": 18857, "answer": [img['id']]}
|
||||
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)
|
||||
print(data)
|
||||
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)
|
||||
@ -89,7 +114,8 @@ def get_photo(address, email):
|
||||
return photos
|
||||
else:
|
||||
for images in os.listdir(main_path):
|
||||
photos.append(main_path + '/' + images)
|
||||
if images.endswith(".jpg") or images.endswith(".jpeg"):
|
||||
photos.append(main_path + '/' + images)
|
||||
return photos
|
||||
|
||||
|
||||
@ -98,6 +124,8 @@ def get_addresses(email):
|
||||
month = datetime.datetime.now().month
|
||||
main_path = os.path.join(os.path.abspath('.'), 'data')
|
||||
path = os.walk(os.path.join(main_path, email, str(month)))
|
||||
if not os.path.exists(os.path.join(main_path, email, str(month))):
|
||||
return f"Не найдена папка с месяцем у пользователя {email}! Проверьте структуру каталога!"
|
||||
for d, dirs, files in path:
|
||||
addresses.append(dirs)
|
||||
if len(addresses[0]) > 0:
|
||||
@ -107,13 +135,15 @@ def get_addresses(email):
|
||||
|
||||
|
||||
def assign_task(session, headers, task, address):
|
||||
complete_task(session, headers, task, address)
|
||||
# complete_task(session, headers, task, address)
|
||||
# DON'T START PROGRAM!!!!
|
||||
#task = session.put('https://knd.mofsreg.ru//api/v1/executions/'+str(task['id'])+'/assign', headers=headers)
|
||||
#if task.status_code == 200:
|
||||
# pass
|
||||
#else:
|
||||
# print(f"Не смогли получить задание {task['id']}!")
|
||||
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):
|
||||
@ -140,30 +170,40 @@ def get_task(session, headers):
|
||||
for address in addresses:
|
||||
# need split enterance from address
|
||||
search = address[:-4]
|
||||
print(search)
|
||||
# print(search)
|
||||
data = {'search': search}
|
||||
tasks = session_t.post('https://knd.mosreg.ru//api/v1/executions',
|
||||
headers=headers,
|
||||
data=data
|
||||
)
|
||||
json_tasks = tasks.json()
|
||||
get_t = False
|
||||
# Если есть доступное задание с таким адресом
|
||||
if len(json_tasks['executions_available']) > 0:
|
||||
for n in json_tasks['executions_available']:
|
||||
coord = n['coord']
|
||||
enterances = n['tasks']
|
||||
for execution in enterances:
|
||||
task = {
|
||||
'id': execution['execution_id'],
|
||||
'address': execution['dimensions'][0].get('entity_value_name'),
|
||||
'enterance': execution['dimensions'][2].get('entity_value_name'),
|
||||
'coord': coord
|
||||
}
|
||||
# Принимаем задание
|
||||
if task['enterance'] == address[-2]:
|
||||
address_from_tasks = execution['dimensions'][0].get('entity_value_name')
|
||||
# print(address_from_tasks)
|
||||
# print('Клин г, '+address[:-4])
|
||||
enterance = execution['dimensions'][2].get('entity_value_name')
|
||||
# print(enterance)
|
||||
# print(address[-2])
|
||||
if address_from_tasks == 'Клин г, '+address[:-4] and \
|
||||
enterance[-1] == address[-2]:
|
||||
print(f'Начали выполнение задания по адресу: {address}')
|
||||
task = {
|
||||
'id': execution['execution_id'],
|
||||
'address': execution['dimensions'][0].get('entity_value_name'),
|
||||
'enterance': execution['dimensions'][2].get('entity_value_name'),
|
||||
'coord': coord
|
||||
}
|
||||
# Принимаем задание
|
||||
assign_task(session, headers, task, address)
|
||||
else:
|
||||
print(f"Нет доступных заданий для по адресу: {address}!")
|
||||
get_t = True
|
||||
if not get_t:
|
||||
print(f"Нет доступных заданий для по адресу: {address}!")
|
||||
# Если нет задания с таким адресом
|
||||
else:
|
||||
print(f"Нет доступных заданий для пользователя {headers['uid']} по адресу: {address}")
|
||||
@ -191,7 +231,7 @@ def main():
|
||||
}
|
||||
if response.status_code == 200:
|
||||
# task = {
|
||||
# 'id': 23607882,
|
||||
# 'id': 23799105,
|
||||
# 'address': 'Решетниково рп, ОПМС-1 проезд, 13',
|
||||
# 'enterance': 6,
|
||||
# 'coord': [56.442503, 36.5596493]
|
||||
@ -210,60 +250,8 @@ def main():
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
||||
# headers = response.headers
|
||||
|
||||
# print(item[0]['tasks'])
|
||||
# print(len(item[3]['tasks']))
|
||||
# print(item[3]['coord'])
|
||||
# count = 0
|
||||
# for item in json_exec.get('executions_assigned'):
|
||||
# print(item['tasks'])
|
||||
# if count < 1:
|
||||
# # for n in item['tasks']:
|
||||
# # print(n['dimensions'])
|
||||
# count = count + 1
|
||||
# for task in item.get('tasks'):
|
||||
# pass
|
||||
|
||||
|
||||
# send_image(session, headers, "some")
|
||||
# get_coord(str1)
|
||||
# get_answers(session, headers)
|
||||
# get_questions(session, headers)
|
||||
# print(executions.text)
|
||||
|
||||
def random_string(stringLength):
|
||||
letters = string.ascii_letters
|
||||
digits = string.digits
|
||||
return ''.join(random.choice(letters+digits) for i in range(stringLength))
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
# def get_coord(address):
|
||||
# url = 'https://geocode-maps.yandex.ru/1.x/?format=json&apikey=591be3ec-2816-40ee-b575-08e687d27b37&geocode='+address
|
||||
# coord = requests.get(url)
|
||||
# print(coord.text)
|
||||
|
||||
|
||||
# def get_task(session, task_id, headers):
|
||||
# task = session.get('https://knd.mosreg.ru//api/v1/executions/', headers=headers)
|
||||
# json_task = task.json()
|
||||
# print(json_task)
|
||||
|
||||
|
||||
# def get_answers(session, headers):
|
||||
# answers = session.post('https://knd.mosreg.ru//api/v1/executions/22515485/answers', headers=headers)
|
||||
# json_answers = answers.json()
|
||||
# for ans in json_answers.get('question_chains'):
|
||||
# print(ans)
|
||||
# # print(json_answers)
|
||||
|
||||
|
||||
# def get_questions(session, headers):
|
||||
# question = session.get('https://knd.mosreg.ru//api/v1/executions/22515485/questions', headers=headers)
|
||||
# json_question = question.json()
|
||||
# for s in json_question['selected_chains']:
|
||||
# for n in s['questions']:
|
||||
# print(n['question_components'])
|
||||
|
||||
Loading…
Reference in New Issue
Block a user