Spaces:
Paused
Paused
| import os | |
| def split_massive_file(input_file="words.txt", lines_per_file=200000): | |
| # Check if the giant file exists | |
| if not os.path.exists(input_file): | |
| print(f"β Error: Could not find '{input_file}' in this folder.") | |
| return | |
| print(f"β³ Reading massive file '{input_file}'...") | |
| # Read all lines | |
| with open(input_file, 'r', encoding='utf-8') as f: | |
| # Strip whitespace/newlines to clean it up while reading | |
| lines = [line.strip() for line in f if line.strip()] | |
| total_lines = len(lines) | |
| print(f"β Loaded {total_lines:,} total words.") | |
| # Split and save into chunks | |
| for i in range(0, total_lines, lines_per_file): | |
| chunk = lines[i:i + lines_per_file] | |
| part_num = (i // lines_per_file) + 1 | |
| output_file = f"part{part_num}.txt" | |
| with open(output_file, 'w', encoding='utf-8') as out: | |
| out.write('\n'.join(chunk)) | |
| print(f"π¦ Created {output_file} ({len(chunk):,} words)") | |
| print("\nπ All done! You can now upload these parts to the bot one by one.") | |
| if __name__ == "__main__": | |
| # You can change "words.txt" if your giant file is named something else | |
| # 200000 is the safe limit for a 256MB Redis database | |
| split_massive_file("words.txt", 200000) | |