Advertisement
Python253

data_marker

Mar 1st, 2024 (edited)
825
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.44 KB | None | 0 0
  1. #!/usr/bin/env python3
  2. # Filename: data_marker.py
  3. # Author: Jeoi Reqi
  4. # Data Marker is a simple script to be used along with the Split Data With Markers Python Script
  5. # Script: https://pastebin.com/tEFTfv7s
  6.  
  7. import os
  8.  
  9. # Set Markers At Specified Number Of Lines (Eg;) 100 With Marker "**"
  10. def insert_marker(input_file, output_file, lines_per_marker=100, marker="**"):
  11.     with open(input_file, 'r', encoding='utf-8') as file:
  12.         lines = file.readlines()
  13.  
  14.     total_lines = len(lines)
  15.     total_markers = total_lines // lines_per_marker
  16.  
  17.     print(f"Total number of markers: {total_markers}")
  18.  
  19.     with open(output_file, 'w', encoding='utf-8') as output:
  20.         for i in range(total_markers):
  21.             start_index = i * lines_per_marker
  22.             end_index = min((i + 1) * lines_per_marker, total_lines)
  23.  
  24.             chunk = lines[start_index:end_index]
  25.  
  26.             # Combine the lines into a single string
  27.             combined_data = ''.join(chunk)
  28.  
  29. if __name__ == "__main__":
  30.     current_directory = os.getcwd()
  31.     input_file_path = os.path.join(current_directory, 'isoon_chat.txt')  # Edit Input To Your Desired File Name
  32.     output_file_path = os.path.join(current_directory, 'output_isoon_chat_with_markers.txt')  # Edit Output File Name To Your Desired File Name
  33.  
  34.     insert_marker(input_file_path, output_file_path, lines_per_marker=100, marker="**")  # Insert The Markers
  35.  
  36.     print("Script execution complete.")
  37.  
  38.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement