|
import random
|
|
import pyperclip
|
|
|
|
class ContentGenerator:
|
|
def __init__(self, artist_file="artist.txt", sheet_file="Sheet1.txt"):
|
|
self.artist_lines = self._load_lines(artist_file)
|
|
self.sheet_lines = self._load_lines(sheet_file)
|
|
|
|
@staticmethod
|
|
def _load_lines(filename):
|
|
with open(filename, "r") as file:
|
|
return [line.strip() for line in file.readlines()]
|
|
|
|
def _copy_and_print(self, result):
|
|
pyperclip.copy(result)
|
|
print(result)
|
|
print("\nContent copied to clipboard.")
|
|
|
|
def get_random_artists(self):
|
|
num_lines = random.randint(1, 4)
|
|
artists = random.sample(self.artist_lines, num_lines)
|
|
result = ", ".join(artist for artist in artists)
|
|
self._copy_and_print(result)
|
|
return result
|
|
|
|
def get_anime_screenshot(self):
|
|
line = random.choice(self.sheet_lines)
|
|
splits = line.split(", ")
|
|
insertion_index = 3 if splits[0] in ["1girl", "1boy", "1other"] else 2
|
|
result = f"{', '.join(splits[:insertion_index])}, anime screenshot, {', '.join(splits[insertion_index:])}".rstrip(", ")
|
|
self._copy_and_print(result)
|
|
return result
|
|
|
|
def process_character_lines(self, num_characters, tags=None):
|
|
available_lines = self.sheet_lines.copy()
|
|
selected_lines = []
|
|
|
|
if tags:
|
|
for tag in tags:
|
|
matches = [line for line in available_lines if tag in line]
|
|
if matches:
|
|
line = random.choice(matches)
|
|
selected_lines.append(line)
|
|
available_lines.remove(line)
|
|
|
|
remaining = num_characters - len(selected_lines)
|
|
if remaining > 0:
|
|
all_matches = list(set(line for tag in tags for line in available_lines if tag in line))
|
|
if all_matches:
|
|
selected_lines.extend(random.sample(all_matches, min(remaining, len(all_matches))))
|
|
|
|
remaining = num_characters - len(selected_lines)
|
|
if remaining > 0 and available_lines:
|
|
selected_lines.extend(random.sample(available_lines, min(remaining, len(available_lines))))
|
|
|
|
artists = ", ".join(random.choice(self.artist_lines) for _ in range(random.randint(1, 4)))
|
|
return self._format_characters(selected_lines, artists)
|
|
|
|
def _format_characters(self, lines, artists):
|
|
counts = {"girl": 0, "boy": 0, "other": 0}
|
|
characters = []
|
|
sources = []
|
|
seen_sources = set()
|
|
|
|
for line in lines:
|
|
splits = line.split(", ")
|
|
|
|
|
|
if "no humans" in splits:
|
|
splits.remove("no humans")
|
|
|
|
|
|
char_type = splits[0] if splits[0] in ["1girl", "1boy", "1other"] else "other"
|
|
if char_type == "1girl":
|
|
counts["girl"] += 1
|
|
char_type = "girl"
|
|
elif char_type == "1boy":
|
|
counts["boy"] += 1
|
|
char_type = "boy"
|
|
else:
|
|
counts["other"] += 1
|
|
char_type = "other"
|
|
|
|
|
|
if char_type in ["girl", "boy"]:
|
|
if len(splits) > 2:
|
|
source = splits[2]
|
|
char_name = splits[1]
|
|
tags = splits[3:]
|
|
else:
|
|
source = ""
|
|
char_name = splits[1] if len(splits) > 1 else ""
|
|
tags = []
|
|
else:
|
|
char_name = splits[0]
|
|
source = splits[1] if len(splits) > 1 else ""
|
|
tags = splits[2:] if len(splits) > 2 else []
|
|
|
|
|
|
if source and source not in seen_sources:
|
|
sources.append(source)
|
|
seen_sources.add(source)
|
|
|
|
|
|
character_entry = [char_type]
|
|
if char_name:
|
|
character_entry.append(char_name)
|
|
character_entry.extend(tags)
|
|
characters.append(", ".join(character_entry))
|
|
|
|
count_str = ", ".join(
|
|
f"{count}{key}{'s' if count > 1 else ''}"
|
|
for key, count in counts.items() if count > 0
|
|
) + (", " + ", ".join(sources) if sources else "")
|
|
result = f"{count_str}, {artists} | " + " | ".join(characters)
|
|
self._copy_and_print(result)
|
|
return result
|
|
|
|
def process_default(self, search_term=None):
|
|
lines = [line for line in self.sheet_lines if search_term in line] if search_term else self.sheet_lines
|
|
line = random.choice(lines if lines else self.sheet_lines)
|
|
|
|
splits = line.split(", ")
|
|
insertion_index = 3 if splits[0] in ["1girl", "1boy", "1other"] else 2
|
|
artists = ", ".join(random.sample(self.artist_lines, random.randint(1, 4)))
|
|
result = f"{', '.join(splits[:insertion_index])}, {artists}, {', '.join(splits[insertion_index:])}".rstrip(", ")
|
|
self._copy_and_print(result)
|
|
return result
|
|
|
|
def main():
|
|
generator = ContentGenerator()
|
|
generator.process_default()
|
|
|
|
while True:
|
|
user_input = input("\nEnter 'a' for artists, 'c' for anime, '1-6' [+tags], or search term: ").strip()
|
|
|
|
if user_input == "a":
|
|
generator.get_random_artists()
|
|
elif user_input == "c":
|
|
generator.get_anime_screenshot()
|
|
elif user_input and user_input[0].isdigit():
|
|
if user_input in ["1", "2", "3", "4", "5", "6"]:
|
|
num = int(user_input)
|
|
generator.process_character_lines(num)
|
|
elif " " in user_input:
|
|
parts = user_input.split(maxsplit=1)
|
|
num = min(int(parts[0]), 6)
|
|
tags = [tag.strip() for tag in parts[1].split(',')]
|
|
generator.process_character_lines(num, tags)
|
|
else:
|
|
generator.process_default(user_input)
|
|
else:
|
|
generator.process_default(user_input if user_input else None)
|
|
|
|
if __name__ == "__main__":
|
|
main() |