from connect import * psycopd_file = 'psycopd_con.json' local_file = 'local_device.json' tuya_file='tuya_con.json' def file_base(): try: cursor=connect_base().cursor() cursor.execute('SELECT * FROM upanel_device') except Exception as e: with open(psycopd_file, 'w', encoding='utf-8') as f: json.dump({'error': str(e)}, f) else: with open(psycopd_file, 'w', encoding='utf-8') as f: json.dump({v[0]:v[1:] for k,v in enumerate(cursor.fetchall())}, f, ensure_ascii=False, indent=4) def file_local(): try: with open(local_file, 'w', encoding='utf-8') as f: json.dump(connect_local(), f, ensure_ascii=False, indent=4) except Exception as e: with open(local_file, 'w', encoding='utf-8') as f: json.dump({'error': str(e)}, f) def file_tuya(): try: with open(local_file, 'r', encoding='utf-8') as f: local_device = json.load(f) with open(tuya_file, 'w', encoding='utf-8') as f: json.dump([connect_tuya().get(f"/v1.0/iot-03/devices/{local_device[dev]['id']}") for dev in local_device],f,ensure_ascii=False, indent=4) except Exception as e: with open(tuya_file, 'w', encoding='utf-8') as f: json.dump({'error': str(e)}, f) if __name__ == '__main__': file_base() file_local() file_tuya()