Python script modified for no lightning better_sectors_no_lightning.pyimport os import re import random
def search_replace_in_files(folder_path): # Get a list of all text files in the specified folder file_list = [f for f in os.listdir(folder_path) if f.endswith('.txt')]
# Loop through each file in the folder for file_name in file_list: file_path = os.path.join(folder_path, file_name)
# Read the content of the file with open(file_path, 'r') as file: content = file.readlines()
# Step 1: Collect existing prop numbers (excluding 0) existing_props = set() for line in content: match = re.match(r'PROP;(\d+);', line) if match: prop_num = int(match.group(1)) if prop_num != 0: existing_props.add(prop_num)
# Step 2: Define candidate numbers and filter available ones candidates = [15, 16, 17, 18, 19, 25, 26, 27] available = [num for num in candidates if num not in existing_props] random.shuffle(available) # Shuffle for random assignment avail_idx = 0 # Index to track available numbers
# Step 3: Loop through each line in the file, including the new PROP;0; replacement for i, line in enumerate(content): # New functionality: Replace PROP;0; with a unique number if re.match(r'PROP;0;', line): if avail_idx < len(available): # Use a unique number from available new_num = available[avail_idx] content[i] = re.sub(r'PROP;0;', f'PROP;{new_num};', line) avail_idx += 1 else: # Not enough unique numbers, choose randomly from candidates new_num = random.choice(candidates) content[i] = re.sub(r'PROP;0;', f'PROP;{new_num};', line) # Replace Ring 1 The rest is the same
1 comment
better_sectors_no_lightning.py
import os
The rest is the sameimport re
import random
def search_replace_in_files(folder_path):
# Get a list of all text files in the specified folder
file_list = [f for f in os.listdir(folder_path) if f.endswith('.txt')]
# Loop through each file in the folder
for file_name in file_list:
file_path = os.path.join(folder_path, file_name)
# Read the content of the file
with open(file_path, 'r') as file:
content = file.readlines()
# Step 1: Collect existing prop numbers (excluding 0)
existing_props = set()
for line in content:
match = re.match(r'PROP;(\d+);', line)
if match:
prop_num = int(match.group(1))
if prop_num != 0:
existing_props.add(prop_num)
# Step 2: Define candidate numbers and filter available ones
candidates = [15, 16, 17, 18, 19, 25, 26, 27]
available = [num for num in candidates if num not in existing_props]
random.shuffle(available) # Shuffle for random assignment
avail_idx = 0 # Index to track available numbers
# Step 3: Loop through each line in the file, including the new PROP;0; replacement
for i, line in enumerate(content):
# New functionality: Replace PROP;0; with a unique number
if re.match(r'PROP;0;', line):
if avail_idx < len(available):
# Use a unique number from available
new_num = available[avail_idx]
content[i] = re.sub(r'PROP;0;', f'PROP;{new_num};', line)
avail_idx += 1
else:
# Not enough unique numbers, choose randomly from candidates
new_num = random.choice(candidates)
content[i] = re.sub(r'PROP;0;', f'PROP;{new_num};', line)
# Replace Ring 1