Add parsing of positive group trees
This commit is contained in:
parent
2e6a44c569
commit
39f2f0fafc
1 changed files with 72 additions and 0 deletions
72
recursive_positive_devices/data.py
Normal file
72
recursive_positive_devices/data.py
Normal file
|
|
@ -0,0 +1,72 @@
|
|||
from typing import List
|
||||
|
||||
|
||||
data = {
|
||||
"groups": [
|
||||
{
|
||||
"id": "0193da9f-230e-783c-a372-6de37d9bc618",
|
||||
"name": "Global",
|
||||
"description": "",
|
||||
"subgroups": [
|
||||
{
|
||||
"id": "0193f836-f7f9-74a6-8192-3e4f2f67f7e3",
|
||||
"name": "Москва",
|
||||
"description": "",
|
||||
"parentId": "0193da9f-230e-783c-a372-6de37d9bc618",
|
||||
"subgroups": [
|
||||
{
|
||||
"id": "0193f837-3821-7dbc-a7c9-9d2029de4a15",
|
||||
"name": "СПБ",
|
||||
"description": "",
|
||||
"parentId": "0193f836-f7f9-74a6-8192-3e4f2f67f7e3",
|
||||
"subgroups": [],
|
||||
}
|
||||
],
|
||||
}
|
||||
],
|
||||
},
|
||||
{
|
||||
"id": "0193da9f-230e-783c-a372-6de37d9bc618_2",
|
||||
"name": "Global",
|
||||
"description": "",
|
||||
"subgroups": [
|
||||
{
|
||||
"id": "0193f836-f7f9-74a6-8192-3e4f2f67f7e3_2",
|
||||
"name": "Москва",
|
||||
"description": "",
|
||||
"parentId": "0193da9f-230e-783c-a372-6de37d9bc618_2",
|
||||
"subgroups": [
|
||||
{
|
||||
"id": "0193f837-3821-7dbc-a7c9-9d2029de4a15_2",
|
||||
"name": "СПБ",
|
||||
"description": "",
|
||||
"parentId": "0193f836-f7f9-74a6-8192-3e4f2f67f7e3_2",
|
||||
"subgroups": [],
|
||||
}
|
||||
],
|
||||
}
|
||||
],
|
||||
},
|
||||
]
|
||||
}
|
||||
|
||||
|
||||
def parse_subgroups(list_of_id: List, subgroups: List):
|
||||
if not subgroups:
|
||||
return
|
||||
for group in subgroups:
|
||||
list_of_id.append(group["id"])
|
||||
parse_subgroups(list_of_id, group["subgroups"])
|
||||
|
||||
|
||||
def list_all_group_ids(groups_list: List) -> List:
|
||||
result = []
|
||||
if not groups_list:
|
||||
return result
|
||||
for group_entry in groups_list:
|
||||
result.append(group_entry["id"])
|
||||
parse_subgroups(result, group_entry["subgroups"])
|
||||
return result
|
||||
|
||||
|
||||
print(list_all_group_ids(data["groups"]))
|
||||
Loading…
Reference in a new issue