cmd18946/query3.py
2026-12-06 08:52:17 +01:00

32 lines
1.3 KiB
Python

#!/usr/bin/env python3
import json,sys
try:
import pymysql
except Exception as e:
print('IMPORT_ERR',e); sys.exit()
out={}
try:
c=pymysql.connect(host='172.18.192.197',port=3307,user='root',password='root',connect_timeout=10,read_timeout=120)
except Exception as e:
print('CONN_ERR',e); sys.exit()
cur=c.cursor()
def dump(db,table,keycols):
try:
cur.execute('SHOW COLUMNS FROM `%s`.`%s`'%(db,table)); cols=[r[0] for r in cur.fetchall()]
cur.execute('SELECT * FROM `%s`.`%s`'%(db,table)); rows=[]
for r in cur.fetchall():
d={}
for i,name in enumerate(cols):
v=r[i]
if isinstance(v,(bytes,bytearray)): v=v.decode('utf8','replace')
elif v is not None and not isinstance(v,str): v=str(v)
d[name]=v
rows.append(d)
return {'cols':cols,'count':len(rows),'rows':rows}
except Exception as e:
return {'err':repr(e)}
out['p2p_bitdog_t_firebase']=dump('p2p_bitdog','t_firebase',None)
out['ali_iot_t_google_iap']=dump('ali_iot','t_google_iap',None)
out['ali_iot_t_apple_iap']=dump('ali_iot','t_apple_iap',None)
out['p2p_bitdog_t_google_iap']=dump('p2p_bitdog','t_google_iap',None)
print(json.dumps(out,ensure_ascii=False)[:850000])