search in avialable tasks before assigned tasks

This commit is contained in:
Noretsa 2020-06-16 23:14:11 +03:00
parent 03a3f7cce9
commit 4545cce5be

View File

@ -2,25 +2,31 @@ import requests
import random
import string
import json
import time
# anwer_text = '{"question_chains":[{"id":6145,"questions":[{"id":6559,"question_components":[{"id":18850,"answer":[80634165],"answer_status":null,"end_time":1591866979,"start_time":1591866978},{"id":18851,"answer":{"location":[56.439337,36.557897]},"answer_status":null,"start_time":1591866873,"end_time":1591867165},{"id":18852,"answer":"1","answer_status":null,"start_time":1591867063,"end_time":1591867063}]}]},{"id":6147,"questions":[{"id":6561,"question_components":[{"id":18856,"answer":77,"answer_status":null,"end_time":1591867067,"start_time":1591867067},{"id":18857,"answer":[80639138],"answer_status":null,"end_time":1591867186,"start_time":1591867185}]}]},{"id":6147,"questions":[{"id":6561,"question_components":[{"id":18856,"answer":77,"answer_status":null,"end_time":1591867200,"start_time":1591867200},{"id":18857,"answer":[80639640],"answer_status":null,"end_time":1591867206,"start_time":1591867205}]}]},{"id":6147,"questions":[{"id":6561,"question_components":[{"id":18856,"answer":77,"answer_status":null,"end_time":1591867211,"start_time":1591867211},{"id":18857,"answer":[80640010],"answer_status":null,"end_time":1591867220,"start_time":1591867219}]}]},{"id":6147,"questions":[{"id":6561,"question_components":[{"id":18856,"answer":77,"answer_status":null,"end_time":1591867223,"start_time":1591867223},{"id":18857,"answer":[80640333],"answer_status":null,"end_time":1591867233,"start_time":1591867232}]}]}]}'
# question_text = ''
def get_enterance_and_coord(session, headers, execution_id):
photo_id = send_image(session, headers, execution_id)
pass
def send_execution(session, headers):
def send_execution(task, session, headers):
# answers_for_data = [{"id":6145,"questions":[{"id":6559,"question_components":[{"id":18850,"answer":[80634165],"answer_status":null,"end_time":1591866979,"start_time":1591866978},{"id":18851,"answer":{"location":[56.439337,36.557897]},"answer_status":null,"start_time":1591866873,"end_time":1591867165}]}]}]
data = {"question_chains": [
{
"id": '6145',
"questions": get_enterance_and_coord(),
}
]}
pass
# print(task)
# print(time.ctime(1592235230))
get_questions(task.get('id'), session, headers)
def get_questions(id_task, session, headers):
url = 'https://knd.mosreg.ru//api/v1/executions/'+str(id_task)+'/questions'
questions = session.get(url, headers=headers)
json_quest = questions.json()
for q in json_quest['selected_chains']:
print(q['id'])
def send_image(session, headers, url):
@ -37,30 +43,50 @@ def send_image(session, headers, url):
def get_task(session, headers):
"""Получаем все доступные задания. Если в переменную search добавить адрес,
то будет искать этот адрес. Он попадет в
то будет искать этот адрес. Он попадет в
json_tasks['executions_available'],
так что надо понять откуда берем задания. Отсюда можно возвращать
так что надо понять откуда берем задания. Отсюда можно возвращать
все параметры задания:
1 координаты
2 адрес
3 подъезд
4 id_задания"""
session.headers.update({'referer': 'https://knd.mosreg.ru/executions', 'x-platform': 'wb', 'accept': '*/*'})
session_t = session
session_t.headers.update({'referer': 'https://knd.mosreg.ru/executions', 'x-platform': 'wb', 'accept': '*/*'})
search = ''
data = {'search': search}# in search можно положить адрес и выдаст только его
tasks = session.post('https://knd.mosreg.ru//api/v1/executions', headers=headers, data=data)
print(tasks.json())
tasks = session_t.post('https://knd.mosreg.ru//api/v1/executions', headers=headers, data=data)
json_tasks = tasks.json()
print("Всего назначено домов на сегодня: " + str(len(json_tasks['executions_assigned'])))
if len(json_tasks['executions_assigned']) > 0:
for n in json_tasks['executions_assigned']:
coord = n['coord'] # Координаты каждого дома
enterence = n['tasks'] # Подъезды в каждом доме
for execution in enterence:
print(execution['execution_id']) # id задания
print(execution['dimensions'][0].get('entity_value_name')) # Адрес
print(execution['dimensions'][2].get('entity_value_name')) # Подъезд
print(json_tasks['executions_assigned'][0]['coord'])
for n in json_tasks['executions_available']:
coord = n['coord']
enterance = n['tasks']
for execution in enterance:
task = {
'id': execution['execution_id'],
'address': execution['dimensions'][0].get('entity_value_name'),
'enterance': execution['dimensions'][2].get('entity_value_name'),
'coord': coord
}
print(task)
# choose = len(json_tasks['executions_available'])
# print(choose)
# get_t = session.put('https://knd.mosreg.ru//api/v1/executions/23244405/assign', headers=headers)# получаем задание из списка доступных для всех
# print(get_t.text)
# print("Всего назначено домов на сегодня: " + str(len(json_tasks['executions_assigned'])))
# if len(json_tasks['executions_assigned']) > 0:
# for n in json_tasks['executions_assigned']:
# coord = n['coord'] # Координаты каждого дома
# enterence = n['tasks'] # Подъезды в каждом доме
# for execution in enterence:
# task = {
# 'id': execution['execution_id'],
# 'address': execution['dimensions'][0].get('entity_value_name'),
# 'enterance': execution['dimensions'][2].get('entity_value_name'),
# 'coord': coord
# }
# send_execution(task, session, headers)
# break
# break
def main():