Skip to content

Commit

Permalink
fixing lint1
Browse files Browse the repository at this point in the history
  • Loading branch information
alzamer2 committed Dec 13, 2023
1 parent f748569 commit bbd07dc
Showing 1 changed file with 11 additions and 17 deletions.
28 changes: 11 additions & 17 deletions sources/en/w/wuxiacom.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
import re

from pyease_grpc import RpcSession
import time

from lncrawl.core.exeptions import FallbackToBrowser
from lncrawl.models import Chapter, Volume
from lncrawl.templates.browser.basic import BasicBrowserTemplate
from lncrawl.webdriver.elements import By
import selenium

logger = logging.getLogger(__name__)

Expand All @@ -28,8 +28,8 @@ def initialize(self):
self.cleaner.bad_tags.add("hr")
self.bearer_token = None
self.cleaner.unchanged_tags.update(["span"])
self.wuxia_login_info = list()
self.start_download_chapter_body_in_browser = False
self.localstorageuser = 'oidc.user:https://identity.wuxiaworld.com:wuxiaworld_spa'

def login(self, email: str, password: str) -> None:
# Login now will use Bearer Token if supplied as main login method,
Expand All @@ -52,13 +52,10 @@ def login(self, email: str, password: str) -> None:
self.browser.wait("//h2[normalize-space()='Your Profile']", By.XPATH, 10)
self.browser.find("//h2[normalize-space()='Your Profile']", By.XPATH)
storage = LocalStorage(self.browser._driver)
if storage.has('oidc.user:https://identity.wuxiaworld.com:wuxiaworld_spa'):
self.bearer_token = '{token_type} {access_token}'.format(**json.loads(storage['oidc.user:https://identity.wuxiaworld.com:wuxiaworld_spa']))
except:
if storage.has(self.localstorageuser):
self.bearer_token = '{token_type} {access_token}'.format(**json.loads(storage[self.localstorageuser]))
except Exception as e:
logger.debug("login Email: Failed")
self.wuxia_login_info = [email,password]



def read_novel_info_in_scraper(self) -> None:
slug = re.findall(r"/novel/([^/]+)", self.novel_url)[0]
Expand Down Expand Up @@ -180,8 +177,8 @@ def read_novel_info_in_browser(self) -> None:
if self.bearer_token:
storage = LocalStorage(self.browser._driver)
logger.debug("LocalStorage: %s", storage)
if not storage.has('oidc.user:https://identity.wuxiaworld.com:wuxiaworld_spa'):
storage['oidc.user:https://identity.wuxiaworld.com:wuxiaworld_spa'] = '{"access_token":"%s","token_type":"%s"}' % tuple(self.bearer_token.split(" ",1)[::-1])
if not storage.has(self.localstorageuser):
storage[self.localstorageuser] = '{"access_token":"%s","token_type":"%s"}' % tuple(self.bearer_token.split(" ",1)[::-1])
logger.debug("LocalStorage: %s", storage)
self.visit(self.novel_url)
self.browser.wait("#novel-tabs #full-width-tab-2")
Expand Down Expand Up @@ -258,25 +255,22 @@ def read_novel_info_in_browser(self) -> None:
# Close progress bar
bar.close()


def download_chapter_body_in_browser(self, chapter: Chapter) -> str:

# login
if not self.start_download_chapter_body_in_browser:
if self.bearer_token:
self.visit('https://www.wuxiaworld.com/manage/profile/')
storage = LocalStorage(self.browser._driver)
logger.debug("LocalStorage: %s", storage)
if not storage.has('oidc.user:https://identity.wuxiaworld.com:wuxiaworld_spa'):
storage['oidc.user:https://identity.wuxiaworld.com:wuxiaworld_spa'] = '{"access_token":"%s","token_type":"%s"}' % tuple(self.bearer_token.split(" ",1)[::-1])
if not storage.has(self.localstorageuser):
storage[self.localstorageuser] = '{"access_token":"%s","token_type":"%s"}' % tuple(self.bearer_token.split(" ",1)[::-1])
logger.debug("LocalStorage: %s", storage)
self.visit('https://www.wuxiaworld.com/manage/profile/')
try:
self.browser.wait("//h2[normalize-space()='Your Profile']", By.XPATH, 10)
self.browser.find("//h2[normalize-space()='Your Profile']", By.XPATH)
except:
except Exception as e:
logger.debug("login Email: Failed")

self.start_download_chapter_body_in_browser = True
self.visit(chapter.url)
try:
Expand All @@ -285,7 +279,7 @@ def download_chapter_body_in_browser(self, chapter: Chapter) -> str:
if self.bearer_token:
self.browser.wait("//button[normalize-space()='Favorite']", By.XPATH, 10)
self.browser.find("//button[normalize-space()='Favorite']", By.XPATH)
except:
except Exception as e:
logger.debug("error loading chapter (%s) or chapter is locked", str(chapter.url))
content = self.browser.find("chapter-content", By.CLASS_NAME).as_tag()
self.cleaner.clean_contents(content)
Expand Down

0 comments on commit bbd07dc

Please sign in to comment.