V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
xJogger
V2EX  ›  分享发现

安娜档案馆读秀数据的元数据竟然就有 458G

  •  
  •   xJogger · 75 天前 · 1301 次点击
    这是一个创建于 75 天前的主题,其中的信息可能已经有所发展或是发生改变。

    https://zh.annas-archive.org/torrents

    如题,解压前 26G ,解压后 458G

    让 GPT 写了个脚本转到 sqlite ,看看会有多大。

    脚本如下:

    # -*- coding: utf-8 -*-
    import sqlite3
    import json
    
    def create_table_from_jsonl(file_path, db_path):
        # 连接到 SQLite 数据库
        conn = sqlite3.connect(db_path)
        cursor = conn.cursor()
    
        # 读取第一行以推断表结构
        with open(file_path, 'r', encoding='utf-8') as file:
            first_line = file.readline()
            first_record = json.loads(first_line)
            columns = list(first_record.keys())
    
            # 创建具有推断列的表
            columns_definition = ", ".join([f"{col} TEXT" for col in columns])
            cursor.execute(f"CREATE TABLE IF NOT EXISTS data ({columns_definition});")
            conn.commit()
    
        write_count = 0  # 写入计数器
    
        # 插入其余数据
        with open(file_path, 'r', encoding='utf-8') as file:
            for line in file:
                record = json.loads(line)
                placeholders = ", ".join(["?"] * len(columns))
                values = [json.dumps(record.get(col, None)) if isinstance(record.get(col, None), (dict, list)) else record.get(col, None) for col in columns]
    
                # 只在值数量和列数量一致时执行插入操作
                if len(values) == len(columns):
                    cursor.execute(f"INSERT INTO data ({', '.join(columns)}) VALUES ({placeholders});", values)
                    write_count += 1
                    print(f"这是第 {write_count} 次写入")
    
                else:
                    print(f"Skipping record due to mismatched column count: {record}")
    
                # 定期提交以保存更改并释放内存
                if write_count % 1000 == 0:
                    conn.commit()
    
        # 最终提交并关闭连接
        conn.commit()
        conn.close()
    
    # 上传的 JSONL 文件路径
    file_path = '/mnt/data/sample.jsonl'
    # SQLite 数据库文件路径
    db_path = '/mnt/data/sample.db'
    
    # 创建表并插入数据
    create_table_from_jsonl(file_path, db_path)
    
    print("数据已成功写入 SQLite 数据库。")
    
    

    ps V 站这个 markdown 没有语法高亮的么……

    第 1 条附言  ·  74 天前
    我放弃了,只能说转出来的 sqlite 大于我硬盘的剩余空间( 300g )
    2 条回复
    fulajickhz
        1
    fulajickhz  
       75 天前
    他這個讀秀庫最新到哪一年?
    xJogger
        2
    xJogger  
    OP
       74 天前 via Android
    @fulajickhz 不知道了,原来读秀还分版本的么
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   2439 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 24ms · UTC 10:23 · PVG 18:23 · LAX 03:23 · JFK 06:23
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.