mirror of
https://github.com/ThePhaseless/Byparr.git
synced 2025-03-15 09:50:20 +08:00
use const for logging level
This commit is contained in:
parent
613ab2fd40
commit
65f91c3a68
3
main.py
3
main.py
@ -11,6 +11,7 @@ from fastapi.responses import RedirectResponse
|
|||||||
from src.models.requests import LinkRequest, LinkResponse
|
from src.models.requests import LinkRequest, LinkResponse
|
||||||
from src.utils import logger
|
from src.utils import logger
|
||||||
from src.utils.browser import bypass_cloudflare, new_browser
|
from src.utils.browser import bypass_cloudflare, new_browser
|
||||||
|
from src.utils.consts import LOG_LEVEL
|
||||||
from src.utils.extentions import download_extentions
|
from src.utils.extentions import download_extentions
|
||||||
|
|
||||||
download_extentions()
|
download_extentions()
|
||||||
@ -49,4 +50,4 @@ async def read_item(request: LinkRequest):
|
|||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
uvicorn.run(app, host="0.0.0.0", port=8191) # noqa: S104
|
uvicorn.run(app, host="0.0.0.0", port=8191, log_level=LOG_LEVEL) # noqa: S104
|
||||||
|
@ -1,7 +1,8 @@
|
|||||||
import logging
|
import logging
|
||||||
import os
|
|
||||||
|
from src.utils.consts import LOG_LEVEL
|
||||||
|
|
||||||
logger = logging.getLogger("uvicorn.error")
|
logger = logging.getLogger("uvicorn.error")
|
||||||
logger.setLevel(os.getenv("LOG_LEVEL") or logging.INFO)
|
logger.setLevel(LOG_LEVEL)
|
||||||
if len(logger.handlers) == 0:
|
if len(logger.handlers) == 0:
|
||||||
logger.addHandler(logging.StreamHandler())
|
logger.addHandler(logging.StreamHandler())
|
||||||
|
@ -1,18 +1,16 @@
|
|||||||
import os
|
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
import nodriver as webdriver
|
import nodriver as webdriver
|
||||||
from nodriver.core.element import Element
|
from nodriver.core.element import Element
|
||||||
|
|
||||||
from src.utils import logger
|
from src.utils import logger
|
||||||
|
from src.utils.consts import CHALLENGE_TITLES
|
||||||
from src.utils.extentions import downloaded_extentions
|
from src.utils.extentions import downloaded_extentions
|
||||||
from src.utils.utils import CHALLENGE_TITLES
|
|
||||||
|
|
||||||
|
|
||||||
async def new_browser():
|
async def new_browser():
|
||||||
config: webdriver.Config = webdriver.Config()
|
config: webdriver.Config = webdriver.Config()
|
||||||
config.sandbox = False
|
config.sandbox = False
|
||||||
config.headless = bool(os.getenv("HEADLESS"))
|
|
||||||
config.add_argument(f"--load-extension={','.join(downloaded_extentions)}")
|
config.add_argument(f"--load-extension={','.join(downloaded_extentions)}")
|
||||||
|
|
||||||
return await webdriver.start(config=config)
|
return await webdriver.start(config=config)
|
||||||
@ -23,6 +21,7 @@ async def bypass_cloudflare(page: webdriver.Tab):
|
|||||||
while True:
|
while True:
|
||||||
await page
|
await page
|
||||||
await page.wait(0.5)
|
await page.wait(0.5)
|
||||||
|
logger.debug(page.target.title)
|
||||||
if page.target.title not in CHALLENGE_TITLES:
|
if page.target.title not in CHALLENGE_TITLES:
|
||||||
return challenged
|
return challenged
|
||||||
if not challenged:
|
if not challenged:
|
||||||
|
@ -1,5 +1,10 @@
|
|||||||
|
import logging
|
||||||
|
import os
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
|
LOG_LEVEL = os.getenv("LOG_LEVEL") or "INFO"
|
||||||
|
LOG_LEVEL = logging.getLevelName(LOG_LEVEL)
|
||||||
|
|
||||||
CHALLENGE_TITLES = [
|
CHALLENGE_TITLES = [
|
||||||
# Cloudflare
|
# Cloudflare
|
||||||
"Just a moment...",
|
"Just a moment...",
|
||||||
|
@ -1,24 +0,0 @@
|
|||||||
from venv import logger
|
|
||||||
|
|
||||||
import nodriver as webdriver
|
|
||||||
from nodriver.core.element import Element
|
|
||||||
|
|
||||||
from src.utils.consts import CHALLENGE_TITLES
|
|
||||||
|
|
||||||
|
|
||||||
async def new_browser():
|
|
||||||
config: webdriver.Config = webdriver.Config()
|
|
||||||
config.sandbox = False
|
|
||||||
|
|
||||||
return await webdriver.start(config=config)
|
|
||||||
|
|
||||||
|
|
||||||
async def bypass_cloudflare(page: webdriver.Tab):
|
|
||||||
while True:
|
|
||||||
await page
|
|
||||||
if page.target.title not in CHALLENGE_TITLES:
|
|
||||||
break
|
|
||||||
elem = await page.query_selector(".cf-turnstile-wrapper")
|
|
||||||
if isinstance(elem, Element):
|
|
||||||
logger.info(f"Clicking element: {elem}")
|
|
||||||
await elem.mouse_click()
|
|
Loading…
x
Reference in New Issue
Block a user