Skip to content

Commit

Permalink
Merge pull request #8 from aintp3d0/refactor
Browse files Browse the repository at this point in the history
Combine download and view options
  • Loading branch information
ames0k0 authored Feb 8, 2024
2 parents 1ecc5b9 + c88ef79 commit 74f62e4
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 46 deletions.
8 changes: 3 additions & 5 deletions docs/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = (
Expand Down
100 changes: 59 additions & 41 deletions twice.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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])

Expand All @@ -123,55 +124,72 @@ def main(self):

uw = input('{}{}:? {}'.format(purple, TAB, end))
if uw == '1':
sp_day = input(
'{}{}Set a specific day (<blank> 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 (<blank> 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__':
Expand Down

0 comments on commit 74f62e4

Please sign in to comment.