Spaces:
Paused
Paused
Create split_file.py
Browse files- split_file.py +35 -0
split_file.py
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
|
| 3 |
+
def split_massive_file(input_file="words.txt", lines_per_file=200000):
|
| 4 |
+
# Check if the giant file exists
|
| 5 |
+
if not os.path.exists(input_file):
|
| 6 |
+
print(f"❌ Error: Could not find '{input_file}' in this folder.")
|
| 7 |
+
return
|
| 8 |
+
|
| 9 |
+
print(f"⏳ Reading massive file '{input_file}'...")
|
| 10 |
+
|
| 11 |
+
# Read all lines
|
| 12 |
+
with open(input_file, 'r', encoding='utf-8') as f:
|
| 13 |
+
# Strip whitespace/newlines to clean it up while reading
|
| 14 |
+
lines = [line.strip() for line in f if line.strip()]
|
| 15 |
+
|
| 16 |
+
total_lines = len(lines)
|
| 17 |
+
print(f"✅ Loaded {total_lines:,} total words.")
|
| 18 |
+
|
| 19 |
+
# Split and save into chunks
|
| 20 |
+
for i in range(0, total_lines, lines_per_file):
|
| 21 |
+
chunk = lines[i:i + lines_per_file]
|
| 22 |
+
part_num = (i // lines_per_file) + 1
|
| 23 |
+
output_file = f"part{part_num}.txt"
|
| 24 |
+
|
| 25 |
+
with open(output_file, 'w', encoding='utf-8') as out:
|
| 26 |
+
out.write('\n'.join(chunk))
|
| 27 |
+
|
| 28 |
+
print(f"📦 Created {output_file} ({len(chunk):,} words)")
|
| 29 |
+
|
| 30 |
+
print("\n🎉 All done! You can now upload these parts to the bot one by one.")
|
| 31 |
+
|
| 32 |
+
if __name__ == "__main__":
|
| 33 |
+
# You can change "words.txt" if your giant file is named something else
|
| 34 |
+
# 200000 is the safe limit for a 256MB Redis database
|
| 35 |
+
split_massive_file("words.txt", 200000)
|