import random import pyperclip def read_random_lines(artist_file="artist.txt", sheet_file="Sheet1.txt"): with open(artist_file, "r") as artist, open(sheet_file, "r") as sheet: artist_lines = artist.readlines() sheet_lines = [line.strip() for line in sheet.readlines()] user_input = "" while True: if user_input: matching_lines = [line for line in sheet_lines if user_input in line] if matching_lines: sheet_line = random.choice(matching_lines) else: sheet_line = random.choice(sheet_lines) else: sheet_line = random.choice(sheet_lines) splits = sheet_line.split(", ") if splits[0] in ["1girl", "1boy", "1other"]: insertion_index = 3 else: insertion_index = 2 num_artist_lines = random.randint(1, 4) selected_artist_lines = random.sample(artist_lines, num_artist_lines) pre_artists = ", ".join(splits[:insertion_index]) artist_section = ", ".join(line.strip() for line in selected_artist_lines) post_artists = ", ".join(splits[insertion_index:]) result = f"{pre_artists}, {artist_section}, {post_artists}" if post_artists else f"{pre_artists}, {artist_section}" result = result.rstrip(", ") print(result) pyperclip.copy(result) print("\nContent copied to clipboard.") user_input = input("\nPress Enter for random or type search term...\n").strip() read_random_lines()