From 6066ce41690de4f09e1d667ba5cb62e9431aaba0 Mon Sep 17 00:00:00 2001 From: DengDai <29502593+zzhhxx@users.noreply.github.com> Date: Mon, 8 Dec 2025 13:57:46 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=89=B9=E9=87=8F=E6=8F=90=E4=BA=A4?= =?UTF-8?q?=E4=B8=BE=E6=8A=A5=EF=BC=8C=E6=9C=AA=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- batch_report.py | 86 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 86 insertions(+) create mode 100644 batch_report.py diff --git a/batch_report.py b/batch_report.py new file mode 100644 index 0000000..cc2156e --- /dev/null +++ b/batch_report.py @@ -0,0 +1,86 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +import json +import pymysql +from datetime import datetime + +# 数据库配置 +DB_CONFIG = { + "host": "localhost", + "user": "your_db_user", + "password": "your_db_password", + "database": "your_db_name", + "charset": "utf8mb4" +} + +# 举报配置 +REPORT_CONFIG = { + "reporter_id": 1, # 举报人的用户ID + "reported_pt_site": "站点名称", + "reason_category": "scam", + "description": "详细情况描述", + "evidences": [ + "https://example.com/image1.png", + "https://example.com/image2.jpg" + ] +} + +def load_users(json_file): + with open(json_file, 'r', encoding='utf-8') as f: + return json.load(f) + +def insert_report(cursor, username, email): + now = datetime.utcnow() + cursor.execute( + "INSERT INTO reports (reporter_id, reported_pt_site, reported_username, reported_email, " + "reason_category, description, status, created_at, updated_at) " + "VALUES (%s, %s, %s, %s, %s, %s, 'pending', %s, %s)", + (REPORT_CONFIG["reporter_id"], REPORT_CONFIG["reported_pt_site"], username, email, + REPORT_CONFIG["reason_category"], REPORT_CONFIG["description"], now, now) + ) + return cursor.lastrowid + +def insert_evidences(cursor, report_id): + now = datetime.utcnow() + for url in REPORT_CONFIG["evidences"]: + cursor.execute( + "INSERT INTO evidences (report_id, file_url, file_type, created_at, updated_at) " + "VALUES (%s, %s, 'image_url', %s, %s)", + (report_id, url, now, now) + ) + +def main(): + users = load_users("users.json") + conn = pymysql.connect(**DB_CONFIG) + + try: + cursor = conn.cursor() + print(f"开始批量写入,共 {len(users)} 个用户\n") + + success_count = 0 + for idx, user in enumerate(users, 1): + username = user.get("username") + email = user.get("email") + + if not email: + print(f"[{idx}] 跳过: 缺少邮箱") + continue + + print(f"[{idx}] 写入: {username or '(无)'} ({email})...", end=" ") + + try: + report_id = insert_report(cursor, username, email) + insert_evidences(cursor, report_id) + conn.commit() + print(f"✓ 成功 (ID: {report_id})") + success_count += 1 + except Exception as e: + conn.rollback() + print(f"✗ 失败: {e}") + + print(f"\n完成! 成功: {success_count}/{len(users)}") + finally: + conn.close() + +if __name__ == "__main__": + main()