| @@ 250-277 (lines=28) @@ | ||
| 247 | # --- END NEW HELPER FUNCTION --- |
|
| 248 | ||
| 249 | ||
| 250 | def select_from_categories(categories_config, all_collections, exclusion_set, remaining_slots, regex_patterns): |
|
| 251 | """Selects items from categories based on config (version from user script).""" |
|
| 252 | # This function now relies on the exclusion_set passed in, which includes recently pinned NON-SPECIAL items |
|
| 253 | collections_to_pin = [] |
|
| 254 | config_dict = categories_config if isinstance(categories_config, dict) else {} |
|
| 255 | always_call = config_dict.pop('always_call', True) |
|
| 256 | category_items = config_dict.items() |
|
| 257 | processed_titles_in_this_step = set() |
|
| 258 | for category, collection_names in category_items: |
|
| 259 | if remaining_slots <= 0: break |
|
| 260 | if not isinstance(collection_names, list): continue |
|
| 261 | potential_pins = [ |
|
| 262 | c for c in all_collections |
|
| 263 | if getattr(c, 'title', None) in collection_names |
|
| 264 | and getattr(c, 'title', None) not in exclusion_set # Checks against combined exclusions |
|
| 265 | and not is_regex_excluded(getattr(c, 'title', ''), regex_patterns) |
|
| 266 | and getattr(c, 'title', None) not in processed_titles_in_this_step |
|
| 267 | ] |
|
| 268 | if potential_pins: |
|
| 269 | if always_call or random.choice([True, False]): |
|
| 270 | selected = random.choice(potential_pins) |
|
| 271 | collections_to_pin.append(selected) |
|
| 272 | processed_titles_in_this_step.add(selected.title) |
|
| 273 | exclusion_set.add(selected.title) # Add to exclusion for this cycle |
|
| 274 | logging.info(f"Added '{selected.title}' from category '{category}'") |
|
| 275 | remaining_slots -= 1 |
|
| 276 | if isinstance(categories_config, dict): categories_config['always_call'] = always_call |
|
| 277 | return collections_to_pin, remaining_slots |
|
| 278 | ||
| 279 | ||
| 280 | def fill_with_random_collections(random_collections_pool, remaining_slots): |
|
| @@ 250-277 (lines=28) @@ | ||
| 247 | # --- END NEW HELPER FUNCTION --- |
|
| 248 | ||
| 249 | ||
| 250 | def select_from_categories(categories_config, all_collections, exclusion_set, remaining_slots, regex_patterns): |
|
| 251 | """Selects items from categories based on config (version from user script).""" |
|
| 252 | # This function now relies on the exclusion_set passed in, which includes recently pinned NON-SPECIAL items |
|
| 253 | collections_to_pin = [] |
|
| 254 | config_dict = categories_config if isinstance(categories_config, dict) else {} |
|
| 255 | always_call = config_dict.pop('always_call', True) |
|
| 256 | category_items = config_dict.items() |
|
| 257 | processed_titles_in_this_step = set() |
|
| 258 | for category, collection_names in category_items: |
|
| 259 | if remaining_slots <= 0: break |
|
| 260 | if not isinstance(collection_names, list): continue |
|
| 261 | potential_pins = [ |
|
| 262 | c for c in all_collections |
|
| 263 | if getattr(c, 'title', None) in collection_names |
|
| 264 | and getattr(c, 'title', None) not in exclusion_set # Checks against combined exclusions |
|
| 265 | and not is_regex_excluded(getattr(c, 'title', ''), regex_patterns) |
|
| 266 | and getattr(c, 'title', None) not in processed_titles_in_this_step |
|
| 267 | ] |
|
| 268 | if potential_pins: |
|
| 269 | if always_call or random.choice([True, False]): |
|
| 270 | selected = random.choice(potential_pins) |
|
| 271 | collections_to_pin.append(selected) |
|
| 272 | processed_titles_in_this_step.add(selected.title) |
|
| 273 | exclusion_set.add(selected.title) # Add to exclusion for this cycle |
|
| 274 | logging.info(f"Added '{selected.title}' from category '{category}'") |
|
| 275 | remaining_slots -= 1 |
|
| 276 | if isinstance(categories_config, dict): categories_config['always_call'] = always_call |
|
| 277 | return collections_to_pin, remaining_slots |
|
| 278 | ||
| 279 | ||
| 280 | def fill_with_random_collections(random_collections_pool, remaining_slots): |
|