From 640855323d5459ff8e1774a0b4cdb7d0ebe9b4d8 Mon Sep 17 00:00:00 2001 From: BlueSkyXN <63384277+BlueSkyXN@users.noreply.github.com> Date: Mon, 17 Jul 2023 11:00:06 +0800 Subject: [PATCH] 3.4 --- .github/workflows/Run-Python.yaml | 1 + Scripts/ALL-Lite-Split.py | 35 +++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+) create mode 100644 Scripts/ALL-Lite-Split.py diff --git a/.github/workflows/Run-Python.yaml b/.github/workflows/Run-Python.yaml index 744ef39..883105a 100644 --- a/.github/workflows/Run-Python.yaml +++ b/.github/workflows/Run-Python.yaml @@ -29,6 +29,7 @@ jobs: python Scripts/Merge-Rules-Renew.py python Scripts/Merge-Rules-ALL.py python Scripts/ALL-Lite-Convert.py + python Scripts/ALL-Lite-Split.py - name: Upload ALL-Rule uses: actions/upload-artifact@v2 diff --git a/Scripts/ALL-Lite-Split.py b/Scripts/ALL-Lite-Split.py new file mode 100644 index 0000000..10e580b --- /dev/null +++ b/Scripts/ALL-Lite-Split.py @@ -0,0 +1,35 @@ +import os + +def split_file(filename, chunk_size): + # 创建子目录 /Part + os.makedirs("Part", exist_ok=True) + + # 读取原始文件 + with open(filename, 'r') as file: + data = file.read() + + # 计算切割后的子文件数量 + num_chunks = (len(data) + chunk_size - 1) // chunk_size + + # 切割并保存子文件 + for i in range(num_chunks): + start = i * chunk_size + end = start + chunk_size + chunk_data = data[start:end] + + # 构建子文件名 + file_parts = os.path.splitext(filename) + new_filename = os.path.join("Part", f"{file_parts[0]}-p{i+1}{file_parts[1]}") + + # 保存子文件 + with open(new_filename, 'w') as new_file: + new_file.write(chunk_data) + + print(f"Created chunk file: {new_filename}") + +# 指定要切割的文件和子文件大小(9MB) +file_to_split = "all-lite.txt" +chunk_size = 9 * 1024 * 1024 + +# 调用函数进行切割 +split_file(file_to_split, chunk_size)