File size: 6,412 Bytes
caba9f1
 
 
dd9cdfe
 
 
 
6d2f6d1
dd9cdfe
 
 
 
caba9f1
dd9cdfe
 
 
 
1fdeb7b
dd9cdfe
 
 
 
 
 
1fdeb7b
dd9cdfe
 
 
 
 
 
 
1fdeb7b
dd9cdfe
 
 
1316877
dd9cdfe
 
 
 
 
 
 
1316877
dd9cdfe
 
 
 
 
 
 
 
 
caba9f1
dd9cdfe
 
 
 
 
 
bd8fcb0
309f901
dd9cdfe
 
 
309f901
 
dd9cdfe
 
 
309f901
dd9cdfe
 
 
 
 
 
 
 
 
 
 
309f901
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
dd9cdfe
 
309f901
dd9cdfe
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
bd8fcb0
 
dd9cdfe
 
 
 
 
 
 
 
bd8fcb0
 
 
 
 
 
 
 
 
 
dd9cdfe
 
caba9f1
dd9cdfe
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
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(", ")

            # Remove "no humans" first if present
            if "no humans" in splits:
                splits.remove("no humans")

            # Determine character type early
            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"

            # Handle source and character name based on type
            if char_type in ["girl", "boy"]:  # Standard format: 1girl/boy, name, source
                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:  # Other format: name, source
                char_name = splits[0]  # Keep the original name
                source = splits[1] if len(splits) > 1 else ""
                tags = splits[2:] if len(splits) > 2 else []

            # Add source to sources list
            if source and source not in seen_sources:
                sources.append(source)
                seen_sources.add(source)

            # Construct character entry
            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()