dump_dan_reports.py 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. import pymysql, json, sys
  2. conn = pymysql.connect(host='192.168.16.251', user='zxyj', password='zxyj@123', database='zxyj', charset='utf8mb4')
  3. cur = conn.cursor()
  4. cur.execute('SELECT id, report_type, dimension, draft_status, parsed_items, parsed_suggestions, parsed_summary, parsed_extra FROM dan_report_uploads ORDER BY id')
  5. rows = cur.fetchall()
  6. out = open('E:\\cfc\\dan_all_reports.txt', 'w', encoding='utf-8')
  7. out.write(f"Total reports: {len(rows)}\n")
  8. out.write("=" * 60 + "\n\n")
  9. for row in rows:
  10. rid, rtype, dim, status, items_json, sugg, summ, extra_json = row
  11. out.write(f"=== Report {rid} | type={rtype} dim={dim} status={status} ===\n")
  12. out.write(f"--- Items ({rtype}) ---\n")
  13. if items_json:
  14. items = json.loads(items_json)
  15. for it in items:
  16. cat = it.get('category', '')
  17. if cat in ('auto', 'overall'):
  18. continue
  19. out.write(f" [{cat}] {it.get('name','?')} = {it.get('value','?')}\n")
  20. auto_items = [it for it in items if it.get('category','') == 'auto']
  21. if auto_items:
  22. out.write(f" [auto] (skipping {len(auto_items)} auto items)\n")
  23. else:
  24. out.write(" (no items)\n")
  25. out.write(f"--- Suggestions ---\n")
  26. out.write(f" {sugg or '(empty)'}\n")
  27. out.write(f"--- Summary ---\n")
  28. out.write(f" {summ or '(empty)'}\n")
  29. if extra_json:
  30. extra = json.loads(extra_json)
  31. out.write(f"--- Extra (keys) ---\n")
  32. for k, v in extra.items():
  33. if isinstance(v, dict):
  34. out.write(f" {k}: {json.dumps(v, ensure_ascii=False)}\n")
  35. else:
  36. out.write(f" {k}: {v}\n")
  37. out.write("\n" + "=" * 60 + "\n\n")
  38. out.close()
  39. print("Done. Wrote E:\\cfc\\dan_all_reports.txt")