Skip to content

Commit

Permalink
Change
Browse files Browse the repository at this point in the history
Chaned:
- convert_objects now converts instead of for every sub dict were wrapped inside list it will go through the whole object and make key for every item in the list based on this key: PARENT_CHILD
  • Loading branch information
Makhuta committed Mar 16, 2024
1 parent 00afdf0 commit f535ece
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions custom_components/honeygain_scrapper/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,18 @@ def setup_client(hass: HomeAssistantType, username: CONF_USERNAME, password: CON

return client

def convert_objects(object: Dict[str, Any]) -> Dict[str, Any]:
data = {}
for key in object:
item = object[key]
if type(item) == dict:
data[key] = [convert_objects(item)]
else:
data[key] = item
def convert_objects(data) -> Dict[str, Any]:
if type(data) == dict:
obj = {}
for (keyOuter, valueOuter) in data.items():
converted = convert_objects(valueOuter)
if type(converted) == dict:
for (keyInner, valueInner) in converted.items():
obj[f'{keyOuter}_{keyInner}'] = valueInner
else:
obj[keyOuter] = converted
return obj

return data

def sanitize_text(input_text):
Expand Down

0 comments on commit f535ece

Please sign in to comment.