From 369faea1c35caec7ded96591f7cabe65a265e1c1 Mon Sep 17 00:00:00 2001 From: Thephaseless Date: Mon, 25 Nov 2024 10:55:40 +0000 Subject: [PATCH] add cache, pip, progress and fix bypass --- .github/workflows/docker-publish.yml | 9 ++++++++- main.py | 4 ++-- poetry.lock | 15 ++++++++++++++- pyproject.toml | 1 + 4 files changed, 25 insertions(+), 4 deletions(-) diff --git a/.github/workflows/docker-publish.yml b/.github/workflows/docker-publish.yml index fa6b62a..52091e9 100644 --- a/.github/workflows/docker-publish.yml +++ b/.github/workflows/docker-publish.yml @@ -30,6 +30,7 @@ jobs: uses: actions/setup-python@v5 with: python-version: "3.12" + cache: "pip" - name: Set up Poetry run: pip install poetry @@ -55,7 +56,13 @@ jobs: rm ./google-chrome-stable_current_amd64.deb - name: Run tests - run: poetry run pytest --retries 3 --retry-delay 5 + run: poetry run pytest --retries 2 --show-progress + + - name: Upload screenshots if tests fail + if: failure() + uses: actions/upload-artifact@v4 + with: + path: screenshots build: needs: test diff --git a/main.py b/main.py index 1190919..2a87a36 100644 --- a/main.py +++ b/main.py @@ -60,17 +60,17 @@ def read_item(request: LinkRequest): source_bs = BeautifulSoup(source, "html.parser") title_tag = source_bs.title logger.info(f"Got webpage: {request.url}") - if title_tag in src.utils.consts.CHALLENGE_TITLES: + if title_tag and title_tag.string in src.utils.consts.CHALLENGE_TITLES: logger.info("Challenge detected") sb.uc_gui_click_captcha() logger.info("Clicked captcha") - sb.save_screenshot("screenshot.png") source = sb.get_page_source() source_bs = BeautifulSoup(source, "html.parser") title_tag = source_bs.title if title_tag and title_tag.string in src.utils.consts.CHALLENGE_TITLES: + sb.save_screenshot(f"./screenshots/{request.url}.png") raise HTTPException( status_code=500, detail="Could not bypass challenge" ) diff --git a/poetry.lock b/poetry.lock index 25684b2..91179b7 100644 --- a/poetry.lock +++ b/poetry.lock @@ -1324,6 +1324,19 @@ files = [ [package.dependencies] pytest = "*" +[[package]] +name = "pytest-progress" +version = "1.3.0" +description = "pytest plugin for instant test progress status" +optional = false +python-versions = "*" +files = [ + {file = "pytest_progress-1.3.0.tar.gz", hash = "sha256:b2a6cd0b0cd8b50b19f56777402835e546dc8404eb7fa77ac2ace9dc719ec50e"}, +] + +[package.dependencies] +pytest = ">=2.7" + [[package]] name = "pytest-rerunfailures" version = "14.0" @@ -2182,4 +2195,4 @@ h11 = ">=0.9.0,<1" [metadata] lock-version = "2.0" python-versions = "^3.12" -content-hash = "15aa6bc34351d1ba1a293b12f8979d58d1d1b6d2716eec78b3de581dd59f53d4" +content-hash = "b14c2514cac9868f24705f98bfe5aaae06ed4b21508b9e4622ada2938338b525" diff --git a/pyproject.toml b/pyproject.toml index 6f155a6..8ca83bf 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -18,6 +18,7 @@ seleniumbase = "^4.32.12" pyautogui = "^0.9.54" beautifulsoup4 = "^4.12.3" pytest-retry = "^1.6.3" +pytest-progress = "^1.3.0" [build-system]