Sh1Fu / Netlab

A simple python script for working with Netlab API
2 stars 0 forks source link

Rework find_count function from Netlab_UpdatePrice class #7

Closed Sh1Fu closed 2 years ago

Sh1Fu commented 2 years ago
    def find_count(self, id: str, cat: dict) -> tuple:
        category_ids = list()
        index = 0
        tmp_index = 0
        while (cat['catalogResponse']['data']["category"][index]["id"] != id):
            index += 1
        current_dict = cat['catalogResponse']['data']["category"][index]
        category_ids.append(current_dict["id"])
        while (current_dict["parentId"] != "0" and int(current_dict["id"]) >= 30):
            tmp_index = 0
            try:
                while current_dict["parentId"] != cat['catalogResponse']['data']["category"][tmp_index]["id"] and tmp_index < len(cat['catalogResponse']['data']["category"]):
                    tmp_index += 1
            except BaseException:
                # print(tmp_index, index, current_dict, cat['catalogResponse']['data']["category"][tmp_index])
                break
            index = tmp_index
            current_dict = cat['catalogResponse']['data']["category"][index]
            category_ids.append(current_dict["id"])

Problem with IndexError and Zero Count issue #5

FIx the idea of working with static catalog.json