1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
| import json import pandas as pd from tqdm import tqdm
from webserver.iot.iot_sdk.baidu_text_transAPI import baidu_trans
json_data = []
with open("HomeAssistant_all_services.json", "r") as json_file: json_data = json.load(json_file)
excel_data = []
total_fields = sum(len(service_info.get("fields", {})) for item in json_data for service_info in item["services"].values())
with tqdm(total=total_fields, desc="Processing fields") as pbar: for item in json_data: domain = item.get("domain") services = item.get("services")
for service_name, service_info in services.items(): service_description = service_info.get("description", "") fields = service_info.get("fields", "") field_name = '' selector = '' filter = '' example = '' advanced = '' required = '' name = '' field_description = '' service_description_translate = baidu_trans(service_description) service_description = service_description + "\\n" + service_description_translate if fields: for field_name, field_info in fields.items(): selector = field_info.get("selector", "") filter = field_info.get("filter", "") example = field_info.get("example", "") advanced = field_info.get("advanced", "") required = field_info.get("required", "") field_description = field_info.get("description", "") field_description_translate = baidu_trans(field_description,) field_description = field_description + "\\n" + field_description_translate excel_data.append( [domain, service_name, service_description, field_name, selector, filter, example, advanced, required, field_description]) pbar.update(1) else: excel_data.append( [domain, service_name, service_description, field_name, selector, filter, example, advanced, required, field_description]) pbar.update(1)
df = pd.DataFrame(excel_data, columns=["domain", "services", "service_description", "fields", "selector", "filter", "example", "advanced", "required", "field_description"])
df.to_excel("HomeAssistant_all_services.xlsx", index=False)
|