From 39f2f0fafcf39ce84cddf78023aa2d86ce0795e2 Mon Sep 17 00:00:00 2001 From: pro100ton Date: Wed, 2 Jul 2025 11:45:02 +0300 Subject: [PATCH] Add parsing of positive group trees --- recursive_positive_devices/data.py | 72 ++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 recursive_positive_devices/data.py diff --git a/recursive_positive_devices/data.py b/recursive_positive_devices/data.py new file mode 100644 index 0000000..582857b --- /dev/null +++ b/recursive_positive_devices/data.py @@ -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"]))