Exemplo n.º 1
0
def start():
    try:
        asyncio.get_event_loop().run_until_complete(main())
    except KeyboardInterrupt:
        clear_line()
        print('Stop the script...')
        show()
    except Exception as e:
        print_error(str(e))
        show()
Exemplo n.º 2
0
 async def __start_spinner(self):
     is_first_iter = True
     while True:
         for item in self.dots:
             text = '' if self.text is None else self.text
             if is_first_iter:
                 is_first_iter = False
             else:
                 clear_line()
             print('\033[92m' + item + '\033[0m ' + text)
             await asyncio.sleep(0.08)
    def __update_progress_bar(self):
        terminal_size = os.get_terminal_size(0).columns
        place_to_print = terminal_size - len(self.prefix) - 8 - 14 - 14
        percentage = 100 * (self.iteration / float(self.total))
        filled_length = int(place_to_print * self.iteration // self.total)
        additional_progress = self.__progress_bar_chars[int(
            ((place_to_print * self.iteration / self.total) % 1) / (1 / 7))]
        progress_chars = '█' * filled_length + additional_progress + ' ' * (
            place_to_print - filled_length - 1)

        to_print = f"{self.prefix} [{progress_chars}] {percentage:.2f}%{self.__speed_value}{self.__speed_eta}"
        print(f"{to_print}{(terminal_size - len(to_print)) * ' '}", end='\r')

        if self.iteration == self.total:
            print()
            clear_line()
            self.is_started = False
Exemplo n.º 4
0
async def main():
    setproctitle.setproctitle('AlphacodersDownloader')

    if len(sys.argv) <= 1:
        url = ''
        while 'https://' not in url and 'alphacoders.com' not in url:
            url = input(
                'Please enter the download url (e.g. '
                'https://wall.alphacoders.com/search.php?search=sword+art+online). > '
            ).replace(' ', '')
            clear_line()

        path = ''
        while os.access(os.path.dirname(path), os.W_OK) is False:
            path = input(
                'Please enter the folder where the images are saved (e.g. ~/downloads/wallpapers/). > '
            )
            clear_line()

        with HiddenCursor() as _:
            async with aiohttp.ClientSession() as client_session:
                await AlphacodersDownloader(url, path, client_session).start()
    else:
        parser = ArgumentsBuilder(
            'A script for download wallpapers on https://alphacoders.com/.',
            'alphacoders-downloader')

        parser.add_argument('-S',
                            action=CommandsHandler().download,
                            description='Download wallpapers.',
                            command_usage='-S wallpapers_url -P path')
        parser.add_argument('-V',
                            action=CommandsHandler.get_version,
                            description='Get version infos.',
                            command_usage='-V')
        with HiddenCursor() as _:
            await parser.build()
 def print_error(self, text: str):
     if self.is_started:
         print()
         clear_line()
     print('\033[91m' + text + '\033[0m')
Exemplo n.º 6
0
 def stop(self):
     if self.task is not None:
         self.task.cancel()
         clear_line()