diff --git a/.github/workflows/ci_docker_fish.yaml b/.github/workflows/ci_docker_fish.yaml index 4731445..80b91d4 100644 --- a/.github/workflows/ci_docker_fish.yaml +++ b/.github/workflows/ci_docker_fish.yaml @@ -4,10 +4,10 @@ on: workflow_dispatch: push: branches: - - hello-world +# - update-challenge - main paths-ignore: - # - ".github/**" + - ".github/**" - "README.md" - "LICENSE" - ".gitignore" diff --git a/.github/workflows/samples/container.yaml b/.github/workflows/samples/docker-compose.yaml similarity index 68% rename from .github/workflows/samples/container.yaml rename to .github/workflows/samples/docker-compose.yaml index 90c89e4..2c07c6f 100644 --- a/.github/workflows/samples/container.yaml +++ b/.github/workflows/samples/docker-compose.yaml @@ -1,4 +1,3 @@ -# /home/epic/docker-compose.yaml version: "3.7" services: @@ -7,8 +6,8 @@ services: init: true command: "python3 claim.py" volumes: - - "/home/epic/user_data_dir/:/home/epic/user_data_dir/" - - "/home/epic/logs/:/home/epic/logs/" + - "/home/epic/user_data_dir:/home/epic/user_data_dir" + - "/home/epic/logs:/home/epic/logs" environment: EPIC_EMAIL: EPIC_PASSWORD: @@ -18,4 +17,4 @@ services: # [🍜] Documentaion # ====================================== # docker-compose https://docs.docker.com/compose/reference/ -# apprise https://github.com/caronc/apprise \ No newline at end of file +# apprise https://github.com/caronc/apprise diff --git a/.github/workflows/samples/source_code.yaml b/.github/workflows/samples/source_code.yaml deleted file mode 100644 index e5abfe3..0000000 --- a/.github/workflows/samples/source_code.yaml +++ /dev/null @@ -1,55 +0,0 @@ -name: I really want to stay at your heart - -on: - workflow_dispatch: -# schedule: -# - cron: "10 23 * * 4,5" - -permissions: - contents: write - -jobs: - setup: - env: - EPIC_EMAIL: ${{ secrets.EPIC_EMAIL }} - EPIC_PASSWORD: ${{ secrets.EPIC_PASSWORD }} - APPRISE_TELEGRAM: ${{ secrets.APPRISE_TELEGRAM }} - RIGHT_NOW: "Automated deployment @ $(date '+%Y-%m-%d %H:%M:%S') Asia/Shanghai" - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - - - name: Clone & Init - run: | - sudo timedatectl set-timezone "Asia/Shanghai" - git clone -b hello-world https://github.com/QIN2DIM/epic-awesome-gamer.git epic - if [ -d "user_data_dir" ];then cp -rfp user_data_dir epic/user_data_dir/; fi - echo "{}" > epic/src/config.json - - - uses: actions/setup-python@v4 - with: - python-version: "3.10" - cache: 'pip' - - - name: Install dependencies - run: | - pip install -r epic/requirements.txt - playwright install firefox - playwright install-deps firefox - - - name: Run tasks - run: | - cd epic/src/ - xvfb-run python claim.py - - - name: Setup GIT user - uses: fregante/setup-git-user@v1 - - - name: Cache browser context - run: | - if [ -d "epic/user_data_dir" ];then cp -rfp epic/user_data_dir .; fi - if [ -d "epic/logs" ];then cp -rfp epic/logs .; fi - rm -rf epic - git add . - git commit -m "${{ env.RIGHT_NOW }}" - git push -f diff --git a/.gitignore b/.gitignore index 0c859fd..1e26644 100644 --- a/.gitignore +++ b/.gitignore @@ -129,10 +129,6 @@ dmypy.json .pyre/ .idea tests/ -.github/workflows/automated.yaml -.github/workflows/automated_claim.yaml -.github/workflows/sync_repo.yaml -docker-compose.yaml archivist/ src/*.json user_data_dir/ diff --git a/requirements.txt b/requirements.txt index ed88e0e..7c54237 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,11 +1,2 @@ -# [install_requires] -bs4>=0.0.1 -beautifulsoup4>=4.10.0 -lxml>=4.9.3 - -# [extra_requires.solver] -hcaptcha-challenger[playwright]==0.7.5 - -# [extra_requires.notify] +hcaptcha-challenger[playwright]==0.7.6.post1 apprise==1.1.0 - diff --git a/src/claim.py b/src/claim.py index cd464cc..4f53502 100644 --- a/src/claim.py +++ b/src/claim.py @@ -13,13 +13,9 @@ from playwright.async_api import BrowserContext from services.agents.epic_games import EpicPlayer, EpicGames from services.agents.epic_games import get_promotions, get_order_history -solver.install(flush_yolo=True) - -player = EpicPlayer.from_account() - promotions = [] - ctx_cookies_is_available = None +player = EpicPlayer.from_account() @logger.catch @@ -60,7 +56,9 @@ async def claim_epic_games(context: BrowserContext): if not ctx_cookies_is_available: logger.info("claim_epic_games", action="Try to flush cookie") if await epic.authorize(page): - await epic.flush_token(context) + cookies = await epic.flush_token(context) + if cookies: + player.cookies = cookies else: logger.error( "claim_epic_games", action="Exit test case", reason="Failed to flush token" @@ -81,10 +79,13 @@ async def claim_epic_games(context: BrowserContext): await epic.claim_weekly_games(page, promotions) +@logger.catch async def run(): prelude() - # Cookie is unavailable or need to process promotions + solver.install(upgrade=True) + + # Cookie is unavailable or need to handle promotions agent = player.build_agent() await agent.execute(sequence=[claim_epic_games], headless=True) diff --git a/src/services/agents/epic_games.py b/src/services/agents/epic_games.py index 666a5e6..a14950c 100644 --- a/src/services/agents/epic_games.py +++ b/src/services/agents/epic_games.py @@ -126,6 +126,7 @@ class EpicGames: break return + logger.success("login", result="token has not expired") return self._solver.status.CHALLENGE_SUCCESS async def authorize(self, page: Page): @@ -137,7 +138,7 @@ class EpicGames: continue logger.critical("Failed to flush token", agent=self.__class__.__name__) - async def flush_token(self, context: BrowserContext): + async def flush_token(self, context: BrowserContext) -> Dict[str, str] | None: page = context.pages[0] await page.goto("https://www.epicgames.com/account/personal", wait_until="networkidle") await page.goto( @@ -145,8 +146,9 @@ class EpicGames: wait_until="networkidle", ) await context.storage_state(path=self.player.ctx_cookie_path) - self.player.ctx_cookies.reload(self.player.ctx_cookie_path) + cookies = self.player.ctx_cookies.reload(self.player.ctx_cookie_path) logger.success("flush_token", path=self.player.ctx_cookie_path) + return cookies async def claim_weekly_games(self, page: Page, promotions: List[Game]): """ diff --git a/src/services/models.py b/src/services/models.py index 5a65e82..c239b1f 100644 --- a/src/services/models.py +++ b/src/services/models.py @@ -56,10 +56,11 @@ class EpicCookie: resp = httpx.get(self.URL_VERIFY_COOKIES, headers=headers, cookies=self.cookies) return resp.status_code == 200 - def reload(self, fp: Path): + def reload(self, fp: Path) -> Dict[str, str] | None: try: data = json.loads(fp.read_text())["cookies"] self.cookies = {ck["name"]: ck["value"] for ck in data} + return self.cookies except (FileNotFoundError, KeyError): pass