Пример #1
0
 def sources_menu(self):
     '''Display the sources menu.'''
     sources = News.get_sources()
     print(f'{str(len(sources))} sources available!')
     action = None
     while action != 0:
         options = '[1] View sources\n'\
                   '[2] Choose sources\n'\
                   '[0] Go back\n'
         action = self.create_menu('SOURCES', options)
         if action == 1:
             [
                 print(f"[{str(i + 1)}] {source['name']}")
                 for i, source in sources.items()
             ]
             selection = 'All' if self.source_ids == '' else [
                 sources[i]['name'] for i in sources
                 if sources[i]['id'] in self.source_ids
             ]
             print(
                 f'\n{self.Fore.YELLOW}{self.Style.BRIGHT}Current sources: {selection}{self.Style.RESET_ALL}'
             )
         elif action == 2:
             new_ids = ''
             while new_ids == '':
                 new_ids = self.yellow_input(
                     'Enter comma separated list of source #s (or `All`)')
                 print(self.Style.RESET_ALL)
             if new_ids.lower() == 'all':
                 self.source_ids = ''
                 self.success('Sources set!')
             else:
                 try:
                     new_ids = set(map(int, new_ids.split(',')))
                     new_ids = [sources[i - 1]['id'] for i in new_ids]
                 except:
                     self.error(self.INVALID)
                     continue
                 self.source_ids = new_ids
                 self.success('Sources set!')
         elif action == 0:
             break
         else:
             self.error(self.INVALID)