| 12345678910111213141516171819202122232425262728293031323334353637383940414243 |
- import pymysql, json, sys
- conn = pymysql.connect(host='192.168.16.251', user='zxyj', password='zxyj@123', database='zxyj', charset='utf8mb4')
- cur = conn.cursor()
- cur.execute('SELECT id, report_type, dimension, draft_status, parsed_items, parsed_suggestions, parsed_summary, parsed_extra FROM dan_report_uploads ORDER BY id')
- rows = cur.fetchall()
- out = open('E:\\cfc\\dan_all_reports.txt', 'w', encoding='utf-8')
- out.write(f"Total reports: {len(rows)}\n")
- out.write("=" * 60 + "\n\n")
- for row in rows:
- rid, rtype, dim, status, items_json, sugg, summ, extra_json = row
- out.write(f"=== Report {rid} | type={rtype} dim={dim} status={status} ===\n")
- out.write(f"--- Items ({rtype}) ---\n")
- if items_json:
- items = json.loads(items_json)
- for it in items:
- cat = it.get('category', '')
- if cat in ('auto', 'overall'):
- continue
- out.write(f" [{cat}] {it.get('name','?')} = {it.get('value','?')}\n")
- auto_items = [it for it in items if it.get('category','') == 'auto']
- if auto_items:
- out.write(f" [auto] (skipping {len(auto_items)} auto items)\n")
- else:
- out.write(" (no items)\n")
- out.write(f"--- Suggestions ---\n")
- out.write(f" {sugg or '(empty)'}\n")
- out.write(f"--- Summary ---\n")
- out.write(f" {summ or '(empty)'}\n")
- if extra_json:
- extra = json.loads(extra_json)
- out.write(f"--- Extra (keys) ---\n")
- for k, v in extra.items():
- if isinstance(v, dict):
- out.write(f" {k}: {json.dumps(v, ensure_ascii=False)}\n")
- else:
- out.write(f" {k}: {v}\n")
- out.write("\n" + "=" * 60 + "\n\n")
- out.close()
- print("Done. Wrote E:\\cfc\\dan_all_reports.txt")
|