11import logging
2+ from collections import defaultdict
23from collections .abc import Generator
34from enum import Enum
45from platform import python_version
56from typing import Annotated , Final , Protocol , TypeVar
67
8+ from questionary import Choice , select
79from typer import Abort , Argument , Context , Exit , Option , Typer
810
911from mediux_posters import __project__ , __version__ , get_cache_root , setup_logging
@@ -79,6 +81,7 @@ def setup(
7981
8082
8183class MediuxSet (Protocol ):
84+ set_title : str
8285 username : str
8386
8487
@@ -87,9 +90,29 @@ def filter_sets(
8790) -> Generator [T ]:
8891 if not set_list :
8992 return
93+
94+ sets_by_user : dict [str , list [T ]] = defaultdict (list )
95+ for x in set_list :
96+ sets_by_user [x .username ].append (x )
97+
9098 # Priority usernames first
9199 for username in priority_usernames :
92- yield from [x for x in set_list if x .username == username ]
100+ user_sets = sets_by_user .get (username , [])
101+ if not user_sets :
102+ continue
103+
104+ while user_sets :
105+ if len (user_sets ) == 1 :
106+ yield user_sets .pop (0 )
107+ else :
108+ choices = [Choice (title = x .set_title , value = x ) for x in user_sets ]
109+ selected = select (f"Multiple sets found from '{ username } '" , choices = choices ).ask ()
110+ if selected :
111+ yield selected
112+ user_sets = [x for x in user_sets if x != selected ]
113+ else :
114+ raise Abort
115+
93116 if not only_priority_usernames :
94117 # Remaining sets
95118 yield from [x for x in set_list if x .username not in priority_usernames ]
0 commit comments