Skip to content

Commit

Permalink
Fix small bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
dipu-bd committed Dec 2, 2018
1 parent 801e530 commit 120cdbf
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 48 deletions.
9 changes: 2 additions & 7 deletions lightnovel_crawler/app/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,8 @@ def start_app(choice_list):

if not instance:
url_not_recognized(choice_list)
return
# end if

if instance:
try:
Program().run(instance)
except:
instance = None
# end try
# end if
Program().run(instance)
# end def
21 changes: 1 addition & 20 deletions lightnovel_crawler/app/arguments.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,26 +9,7 @@ class ArgReader:
def build(self):
parser = argparse.ArgumentParser(
epilog='~' * LINE_SIZE,
usage=textwrap.dedent(
'''
lncrawl [-h | --help]
[-v | --version]
[-l | --log]
[-s NOVEL_PAGE | --source NOVEL_PAGE]
[-f | --force]
[-b | --byvol]
[--login USER PASSWD]
[
--all |
--first COUNT |
--last COUNT |
--volume START STOP |
--range FROM TO |
--page START STOP |
--volumes [N [N ...]] |
--chapters [URL [URL ...]]
]
'''),
usage='\tlncrawl [options...]\n\tlightnovel-crawler [options...]'
)
parser.add_argument('-v', '--version', action='version',
version='Lightnovel Crawler ' + os.environ['version'])
Expand Down
5 changes: 3 additions & 2 deletions lightnovel_crawler/app/display.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,13 @@ def description():


def epilog():
print()
print('-' * LINE_SIZE)

print(' ' + Icons.LINK, 'Source:', Fore.CYAN,
print(' ' + Icons.LINK, Fore.CYAN,
'https://github.com/dipu-bd/lightnovel-crawler', Fore.RESET)

print(' ' + Icons.HANDS, 'Say Thanks:', Fore.CYAN,
print(' ' + Icons.HANDS, Fore.CYAN,
'https://saythanks.io/to/dipu-bd', Fore.RESET)

print('=' * LINE_SIZE)
Expand Down
6 changes: 3 additions & 3 deletions lightnovel_crawler/app/program.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def chapter_range(self):
start, stop = range_using_urls(self.crawler)
self.chapters = self.crawler.chapters[start:(stop + 1)]
elif res == 'range':
start, stop = range_using_urls(self.crawler)
start, stop = range_using_index(chapter_count)
self.chapters = self.crawler.chapters[start:(stop + 1)]
elif res == 'volumes':
selected = range_from_volumes(self.crawler.volumes)
Expand All @@ -79,10 +79,10 @@ def chapter_range(self):
if selected.count(chap['volume']) > 0
]
elif res == 'chapters':
selected = range_from_chapters(self.crawler.chapters)
selected = range_from_chapters(self.crawler)
self.chapters = [
chap for chap in self.crawler.chapters
if selected.count(chap['id']) > 0 or selected.count(chap['url']) > 0
if selected.count(chap['id']) > 0
]
# end if

Expand Down
42 changes: 26 additions & 16 deletions lightnovel_crawler/app/prompts.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ def range_using_urls(crawler):
if not (start_url and stop_url):
def validator(val):
try:
if crawler.get_chapter_index_of(val) >= 0:
if crawler.get_chapter_index_of(val) > 0:
return True
except:
pass
Expand All @@ -146,10 +146,10 @@ def validator(val):
stop_url = answer['stop_url']
# end if

start = crawler.get_chapter_index_of(start_url)
stop = crawler.get_chapter_index_of(stop_url)
start = crawler.get_chapter_index_of(start_url) - 1
stop = crawler.get_chapter_index_of(stop_url) - 1

return start, stop if start < stop else stop, start
return (start, stop) if start < stop else (stop, start)
# end def


Expand Down Expand Up @@ -181,14 +181,14 @@ def validator(val):
'filter': lambda val: int(val),
},
])
start = answer['start']
stop = answer['stop']
start = answer['start'] - 1
stop = answer['stop'] - 1
else:
start = start - 1
stop = stop - 1
# end if

start = start - 1
stop = stop - 1

return start, stop if start < stop else stop, start
return (start, stop) if start < stop else (stop, start)
# end def


Expand Down Expand Up @@ -230,7 +230,7 @@ def range_from_volumes(volumes, times=0):
# end def


def range_from_chapters(chapters, times=0):
def range_from_chapters(crawler, times=0):
selected = None

if times == 0:
Expand All @@ -245,29 +245,39 @@ def range_from_chapters(chapters, times=0):
'message': 'Choose chapters to download:',
'choices': [
{'name': '%d - %s' % (chap['id'], chap['title'])}
for chap in chapters
for chap in crawler.chapters
],
}
])
selected = [
int(val.split(' ')[0]) for val in answer['chapters']
int(val.split(' ')[0])
for val in answer['chapters']
]
else:
selected = [
crawler.get_chapter_index_of(x)
for x in selected if x
]
# end if

if times < 3 and len(selected) == 0:
return range_from_chapters(chapters, times + 1)
return range_from_chapters(crawler, times + 1)
# end if

selected = [
x for x in selected
if 1 <= x <= len(crawler.chapters)
]

return selected
# end def


def pack_by_volume():
if len(sys.argv) > 1:
return get_args().byvol
# end if

answer = prompt([
answer= prompt([
{
'type': 'confirm',
'name': 'volume',
Expand Down

0 comments on commit 120cdbf

Please sign in to comment.