From b73093584fb5c0dc8921dad4dc1d75e734320e9c Mon Sep 17 00:00:00 2001 From: teffalump <90264+teffalump@users.noreply.github.com> Date: Mon, 17 Aug 2020 15:50:27 -0700 Subject: [PATCH] Update adapter_wuxiaworldco.py Strip non-numeric characters from chapter number before parsing as number. However, allows decimals and parses numbers as floats. Consequently, 'chapter 10.5 - xxx' still can be sorted into correct place. --- fanficfare/adapters/adapter_wuxiaworldco.py | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/fanficfare/adapters/adapter_wuxiaworldco.py b/fanficfare/adapters/adapter_wuxiaworldco.py index a7a015b3..13daf984 100644 --- a/fanficfare/adapters/adapter_wuxiaworldco.py +++ b/fanficfare/adapters/adapter_wuxiaworldco.py @@ -102,19 +102,18 @@ class WuxiaWorldCoSiteAdapter(BaseSiteAdapter): # Sort and deduplicate chapters (some stories in incorrect order and/or duplicates) chapters_data = [] + numbers_regex = re.compile('[^0-9\.]') # Everything except decimal and numbers for ch in chapters: chapter_title = ch.p.get_text() chapter_url = ch['href'] if chapter_title.startswith('Chapter'): - try: - number = int(chapter_title.split()[1]) - except: - continue + target_number = chapter_title.split()[1] else: - try: - number = int(chapter_title.split()[0]) - except: - continue + target_number = chapter_title.split()[0] + try: + number = float(re.sub(numbers_regex, '', target_number)) + except: + continue # Cannot parse chapter number chapters_data.append((number, chapter_title, chapter_url)) chapters_data.sort(key=lambda ch: ch[0])