def menu(): Menu( "What would you like to do?", { 'Updates': updates, 'Favourites': favourites, Menu.seperator(' '): '', 'Refresh': refresh, 'Erase data': reset }).prompt()
def __init__(self, manga: Manga, chapters=None): self.manga = manga self.chapters = chapters self.options = {} self.menu = Menu('Pick an action', self.options) self._construct_menu()
def __init__(self, updates: dict): self.updates = updates self.informative = { f'{key.title} ({len(self.updates[key])})': self.updates[key] for key in self.updates.keys() } mangas = list(self.informative.keys()) manga_prompt_list = alphabetic_prompt_list([manga for manga in mangas]) # exit options manga_prompt_list.extend([Separator(' '), 'Exit']) self._menu = Menu("Updates", manga_prompt_list)
def search(): search = vinput('Enter here to search:') url = codec.search_prefix + search while True: codec.search(url) # mutate options to include page routing choices: List = codec.search_result[:] if codec.previous_page_exists(): choices.insert(0, 'PREVIOUS') if codec.next_page_exists(): choices.append('NEXT') search_answer = Menu('Choose', choices, key=lambda chapter: chapter['name']).prompt() if search_answer == 'PREVIOUS': url = codec.get_page(codec.current_page - 1) continue elif search_answer == 'NEXT': url = codec.get_page(codec.current_page + 1) continue else: for result in codec.search_result: if result['name'] == search_answer: from modules.database.mangas import manga m = models.Manga(result['name'], result['href']) if m.title in manga.databases.keys(): info = manga.databases[m.title].get_info() m.is_manhwa = info.is_manhwa return m
def _construct_menu(self): self.options = {} if not favourite.exist(self.manga): self.options['Add to favourites'] = lambda: self.repeat( favourite.upsert, self.manga) from ..download import select_and_download self.options['Download'] = lambda: select_and_download( self.manga, self.chapters) self.options[ f'[{self.manga.is_manhwa}] Set Manhwa to {not self.manga.is_manhwa}'] = self._toggle if favourite.exist(self.manga): self.options['Remove from favourites'] = lambda: self.repeat( favourite.remove, self.manga) self.menu = Menu('Pick an action', self.options)
class MangaDialog: def __init__(self, manga: Manga, chapters=None): self.manga = manga self.chapters = chapters self.options = {} self.menu = Menu('Pick an action', self.options) self._construct_menu() def prompt(self): while True: try: r = self.menu.prompt() except KeyError as e: break if r: break # reconstruct to deal with changed settings self._construct_menu() def repeat(self, func, *args, **kwargs): func(*args, **kwargs) return True def _construct_menu(self): self.options = {} if not favourite.exist(self.manga): self.options['Add to favourites'] = lambda: self.repeat( favourite.upsert, self.manga) from ..download import select_and_download self.options['Download'] = lambda: select_and_download( self.manga, self.chapters) self.options[ f'[{self.manga.is_manhwa}] Set Manhwa to {not self.manga.is_manhwa}'] = self._toggle if favourite.exist(self.manga): self.options['Remove from favourites'] = lambda: self.repeat( favourite.remove, self.manga) self.menu = Menu('Pick an action', self.options) def _toggle(self): update_is_manhwa(self.manga, not self.manga.is_manhwa) self.manga.is_manhwa = not self.manga.is_manhwa
class UpdatesMenu: def __init__(self, updates: dict): self.updates = updates self.informative = { f'{key.title} ({len(self.updates[key])})': self.updates[key] for key in self.updates.keys() } mangas = list(self.informative.keys()) manga_prompt_list = alphabetic_prompt_list([manga for manga in mangas]) # exit options manga_prompt_list.extend([Separator(' '), 'Exit']) self._menu = Menu("Updates", manga_prompt_list) def prompt(self): # choose a manga manga_title = self._menu.prompt() if manga_title == 'Exit': return # construct new checbox menu for this checkbox_choices = [{ 'name': chapter.title } for chapter in self.informative[manga_title]] selected_names = prompt( dict(type='checkbox', name='updates', message=manga_title, choices=checkbox_choices))['updates'] # nothing selected if not selected_names: return selected = list( filter(lambda chapter: chapter.title in selected_names, self.informative[manga_title])) manga = list( filter( lambda key: self.updates[key] == self.informative[manga_title], self.updates.keys()))[0] with Loader("Parse Info"): manga, all_chapters = manga.parse() from modules.database.models.manga.download import selective_download selective_download(manga, all_chapters, selected, update=True)
def favourites(): # get all favourites favoured = alphabetic_prompt_list(favourite.all(), key=lambda val: val.title) if not favoured: print(title('No favourites')) return options = {} for item in favoured: if isinstance(item, Manga): options[item.title] = lambda: MangaDialog(item).prompt() else: options[item] = '' Menu('Select', options).prompt()