Build(requirements): minify dependencies (#207)

* Build(requirements): minify

* Fix(claim): invalid index of cookies object
This commit is contained in:
QIN2DIM 2023-09-02 01:49:38 +08:00 committed by GitHub
parent 6b099c0922
commit b2e43522c1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 20 additions and 85 deletions

View File

@ -4,10 +4,10 @@ on:
workflow_dispatch:
push:
branches:
- hello-world
# - update-challenge
- main
paths-ignore:
# - ".github/**"
- ".github/**"
- "README.md"
- "LICENSE"
- ".gitignore"

View File

@ -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
# apprise https://github.com/caronc/apprise

View File

@ -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

4
.gitignore vendored
View File

@ -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/

View File

@ -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

View File

@ -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)

View File

@ -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]):
"""

View File

@ -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