Всем доброго времени суток!
Начал изучать этот замечательный язык. В основном он мне нужен для взаимодействия с системой управления такси.
К сути. Делаю запрос к api и получаю json со списком всех активных в данный момент заказов с кучей атрибутов, затем считаю это количество и вывожу:
import json
import hashlib
import urllib3
urllib3.disable_warnings()
host3 = 'https://IP:PORT/common_api/1.0/get_current_orders'
r3 = requests.get(host3, verify=False, headers={'Signature': 'SECRET'})
data = r3.json()
count = sum([len(data['data']['orders'])])
print('Количество активных заказов в системе всего: ', count)
Получаю при этом JSON выглядит так:
{
"code":0,
"descr":"OK",
"data":{
"orders":[
{
"id":890011,
"state_id":7,
"state_kind":"client_inside",
"server_time_offset":0,
"start_time":"20201109000700",
"source_time":"20201109000700",
"source":"Заказ с бордюра",
"source_lat":0.0,
"source_lon":0.0,
"destination":"Заказ с бордюра",
"destination_lat":0.0,
"destination_lon":0.0,
"stops":[
],
"customer":"",
"passenger":"",
"crew_id":21197,
"prior_crew_id":0,
"driver_id":21004,
"car_id":21119,
"phone":"",
"client_id":0,
"tariff_id":15,
"order_crew_group_id":7,
"creation_way":"driver",
"client_employee_id":0,
"is_prior":False,
"is_really_prior":False,
"email":"",
"prior_to_current_before_minutes":0,
"flight_number":""
},
{
"id":890277,
"state_id":11,
"state_kind":"client_inside",
"server_time_offset":0,
"start_time":"20201109081147",
"source_time":"20201109082041",
"source":"Новая 3-я ул. /Ярцево/, 3 *ДОМ 8.ЧС",
"source_lat":55.069675,
"source_lon":32.660976,
"destination":"Смоленск",
"destination_lat":54.791492,
"destination_lon":32.022835,
"stops":[
],
"customer":"Андрей ",
"passenger":"",
"crew_id":19706,
"prior_crew_id":0,
"driver_id":19624,
"car_id":19651,
"phone":"89303058504",
"client_id":2747,
"tariff_id":22,
"order_crew_group_id":7,
"creation_way":"operator",
"client_employee_id":0,
"is_prior":False,
"is_really_prior":False,
"email":"",
"prior_to_current_before_minutes":0,
"flight_number":""
},
{
"id":890308,
"state_id":1,
"state_kind":"new_order",
"server_time_offset":0,
"start_time":"20201109083558",
"source_time":"20201109104500",
"source":"Нагать * СМОЛЕНСКАЯ 32",
"source_lat":54.674381,
"source_lon":32.1422,
"destination":"Роддом(Покровка) /Смоленск/ *ул. Фрунзе, 40/5*",
"destination_lat":54.806183,
"destination_lon":32.046394,
"stops":[
],
"customer":"ъ",
"passenger":"",
"crew_id":0,
"prior_crew_id":17310,
"driver_id":0,
"car_id":0,
"phone":"89156453490",
"client_id":53786,
"tariff_id":40,
"order_crew_group_id":2,
"creation_way":"operator",
"client_employee_id":0,
"is_prior":True,
"is_really_prior":True,
"email":"",
"prior_to_current_before_minutes":20,
"flight_number":""
},
{
"id":890319,
"state_id":11,
"state_kind":"client_inside",
"server_time_offset":0,
"start_time":"20201109084218",
"source_time":"20201109085153",
"source":"Марии Октябрьской ул. /Смоленск/, 4б * п.1* вас не видят!!!!!!СВЯЖИТЕСЬ!!!",
"source_lat":54.764038,
"source_lon":32.062035,
"destination":"Беляева ул. /Смоленск/, 6",
"destination_lat":54.793442,
"destination_lon":32.049812,
"stops":[
],
"customer":"",
"passenger":"",
"crew_id":16986,
"prior_crew_id":0,
"driver_id":16984,
"car_id":16986,
"phone":"89966298818",
"client_id":193584,
"tariff_id":40,
"order_crew_group_id":2,
"creation_way":"operator",
"client_employee_id":0,
"is_prior":False,
"is_really_prior":False,
"email":"",
"prior_to_current_before_minutes":0,
"flight_number":""
},
{
"id":890327,
"state_id":11,
"state_kind":"client_inside",
"server_time_offset":0,
"start_time":"20201109084620",
"source_time":"20201109085548",
"source":"Фрунзе ул. /Смоленск/, 64* П 1",
"source_lat":54.81494,
"source_lon":32.040125,
"destination":"25 Сентября ул. /Смоленск/, 28",
"destination_lat":54.766571,
"destination_lon":32.076384,
"stops":[
],
"customer":"Без имени",
"passenger":"",
"crew_id":17655,
"prior_crew_id":0,
"driver_id":17653,
"car_id":17655,
"phone":"89190417754",
"client_id":136947,
"tariff_id":40,
"order_crew_group_id":2,
"creation_way":"operator",
"client_employee_id":0,
"is_prior":False,
"is_really_prior":False,
"email":"",
"prior_to_current_before_minutes":0,
"flight_number":""
},
{
"id":890330,
"state_id":11,
"state_kind":"client_inside",
"server_time_offset":0,
"start_time":"20201109084916",
"source_time":"20201109085834",
"source":"Северный 6-й пер. /Смоленск/, 44* аренда",
"source_lat":54.808743,
"source_lon":32.073631,
"destination":"",
"destination_lat":0.0,
"destination_lon":0.0,
"stops":[
],
"customer":"Без имени",
"passenger":"",
"crew_id":21119,
"prior_crew_id":0,
"driver_id":16323,
"car_id":16325,
"phone":"89525394220",
"client_id":192638,
"tariff_id":40,
"order_crew_group_id":2,
"creation_way":"operator",
"client_employee_id":0,
"is_prior":False,
"is_really_prior":False,
"email":"",
"prior_to_current_before_minutes":0,
"flight_number":""
},
Мне необходимо посчитать количество только тех заказов, которые имеют параметр "order_crew_group_id":2
Подскажите, как это сделать?