Do you have a script to export all devices's attributes of an iot.tuya project #412
jnasserifar
started this conversation in
General
Replies: 1 comment
-
Hi @jnasserifar, when you run he setup Wizard, it creates files import json
import csv
input_json_file = 'devices.json'
output_csv_file = 'output.csv'
# List of field names you want to include in the CSV
# category,sub,uuid,mac,product_name,product_id,name,model,icon,biz_type,id,mapping,version,parent,key,sn,ip,node_id
specified_fields = ['product_name', 'id', 'key', 'product_id', 'mac'] # Replace with your desired field names
# Read the JSON file
with open(input_json_file, 'r') as json_file:
data = json.load(json_file)
# Write the data to a CSV file with custom quoting
with open(output_csv_file, 'w', newline='') as csv_file:
writer = csv.DictWriter(
csv_file,
fieldnames=specified_fields,
quoting=csv.QUOTE_MINIMAL, # Quote fields containing special characters
quotechar='"',
delimiter=',',
escapechar='\\'
)
# Write the header row with specified fields
writer.writeheader()
# Write the data rows with only the specified fields
for record in data:
specified_record = {field: json.dumps(value) if isinstance(value, dict) else value
for field, value in record.items() if field in specified_fields}
writer.writerow(specified_record) |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hi,
For documentation and integration purpose I need an export of iot.tuya devices in a project completely.
currently I use API explorer to do extract each device attributes. do you have any solution or script to export them as bulc in a CSV file?
input of script: project name or project ID
export the followin attributes:
Device Name
Device ID
Local Key
Product ID
Mac address
or any other details
Beta Was this translation helpful? Give feedback.
All reactions