diff --git a/docs/config.py b/docs/config.py index 6bc9b77..c61ce76 100644 --- a/docs/config.py +++ b/docs/config.py @@ -31,11 +31,9 @@ """ options = """ - {0}1) Download specific/random Day and Open == {1}~7...40 pics - {1}2) Donwload all Days == {0}120 pages * ~7...40 pics - {0}3) Open specific/random Day from == {1}[{2}] - {1}4) Open all Days from == {0}[{2}] - {0}5) Clear all Days == {1}[{2}]\n + {0}1) Download [a]ll/specific/[r]andom Day and Open == {1}120 days * ~7...40 pics + {0}2) Open [a]ll/specific/[r]andom Day from == {0}[{2}] + {0}3) Delete all Days == {1}[{2}]\n """ JIHYO = ( diff --git a/twice.py b/twice.py index 6884854..7b1a4ce 100644 --- a/twice.py +++ b/twice.py @@ -85,9 +85,10 @@ def get_seconds(self): @_indir - def open_photo(self, seconds): + def open_photo(self, seconds, color): """Open photo with programm *DEFAULT_IMAGE_VIEWER* """ + print(f"{color}{TAB}Opening day: {ACTIVE_DIR}{end}") for file in BASE_DIR.cwd().iterdir(): termin(seconds, file) @@ -100,14 +101,14 @@ def _get_soup(self): def download_day_photos(self): - print(f'\n{purple}{TAB}Day: {ACTIVE_DIR}{end}\n') + print(f'{purple}{TAB}Day: {ACTIVE_DIR}{end}\n') try: soup = self._get_soup() fastprint(f'\n{blue}url >>> {self.base_url}{ACTIVE_DIR}{end}') fastprint(f'{purple}올 트와이스닷컴 :: {soup.find("h2").text}{end}\n') self.download_photo(soup) except HTTPError: - print(f'{TAB}Day {ACTIVE_DIR} is not exists') + print(f'{TAB}{blue}Day: {ACTIVE_DIR} does not exists{end}') except Exception as e: print(f'{TAB}Error: ', e.args[0]) @@ -123,55 +124,72 @@ def main(self): uw = input('{}{}:? {}'.format(purple, TAB, end)) if uw == '1': - sp_day = input( - '{}{}Set a specific day ( as random): {}'.format(purple, TAB, end) - ).strip() - if not sp_day or not sp_day.isdigit(): + while True: + sp_day = input( + '{}{}Set a day number or `r`, `a`: {}'.format(purple, TAB, end) + ).strip() + if sp_day in ('r', 'a'): + break + if sp_day.isdigit(): + break + if sp_day == 'a': + print(f'\n{blue}{TAB}[CTRL + C] to STOP{end}') + for day in range(*self.active_days): + ACTIVE_DIR = str(day) + self.download_day_photos() + exit() + + elif sp_day == 'r': ACTIVE_DIR = str(randint(*self.active_days)) - else: + elif sp_day.isdigit(): ACTIVE_DIR = sp_day self.download_day_photos() seconds = self.get_seconds() - self.open_photo(seconds) + self.open_photo(seconds, purple) + exit() + + if uw == '2': + if not mid: + exit() + print() + colors = cycle((purple, blue)) + for days in batched(mid, DAYS_VIEW_CHUNK): + row = ', '.join(days) + color = next(colors) + print(f"{color}{TAB}{row}{end}") + print() + + while True: + sp_day = input( + '{}{}Set a day number or `r`, `a`: {}'.format(purple, TAB, end) + ).strip() + if sp_day in ('r', 'a'): + break + if sp_day.isdigit(): + break - elif uw == '2': - print(f'{blue}{TAB}[CTRL + C] to STOP{end}') - for day in range(*self.active_days): - ACTIVE_DIR = str(day) - self.download_day_photos() + seconds = self.get_seconds() - if mid: - if uw == '3': - print() + if sp_day == 'a': colors = cycle((purple, blue)) - for days in batched(mid, DAYS_VIEW_CHUNK): - row = ', '.join(days) + for day in mid: + ACTIVE_DIR = day color = next(colors) - print(f"{color}{TAB}{row}{end}") - print() + self.open_photo(seconds, color) + exit() + elif sp_day == 'r': + ACTIVE_DIR = choice(mid) + elif sp_day.isdigit(): + ACTIVE_DIR = sp_day - sp_day = input( - '{}{}Set a specific day ( as random): {}'.format(purple, TAB, end) - ).strip() - if not sp_day or sp_day not in mid: - ACTIVE_DIR = choice(mid) - else: - ACTIVE_DIR = sp_day - - seconds = self.get_seconds() - self.open_photo(seconds) - elif uw == '4': - seconds = self.get_seconds() + self.open_photo(seconds, purple) + + elif uw == '3': + qu = input('{}{}Are you Sure [Y/n] :? {}'.format(purple, TAB, end)).upper() + if qu.startswith('Y'): for day in mid: - ACTIVE_DIR = day - print(f"{TAB}Opening day: {day}") - self.open_photo(seconds) - elif uw == '5': - qu = input('{}{}Are you Sure [Y/n] :? {}'.format(purple, TAB, end)).upper() - if qu.startswith('Y'): - for day in mid: - rmtree(day) + rmtree(day) if __name__ == '__main__':