-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
1. 完成Github Actions每週自動更新黑名單 2. 新增登入檢查功能 3. 更新套件依賴
- Loading branch information
1 parent
d478929
commit d245bca
Showing
9 changed files
with
806 additions
and
134 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
name: update-blacklist | ||
|
||
on: | ||
schedule: | ||
- cron: '0 4 * * 0' | ||
workflow_dispatch: | ||
|
||
jobs: | ||
update-blacklist: | ||
runs-on: ubuntu-latest | ||
environment: update-blacklist | ||
permissions: | ||
contents: write | ||
|
||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v4 | ||
|
||
- name: Install uv | ||
uses: astral-sh/setup-uv@v5 | ||
with: | ||
enable-cache: true | ||
cache-dependency-glob: uv.lock | ||
python-version: 3.13 | ||
|
||
- name: Run Python script | ||
env: | ||
COOKIES_BASE64: ${{ secrets.COOKIES_BASE64 }} | ||
BAHA_USERNAME: ${{ secrets.BAHA_USERNAME }} | ||
run: uv run -m baha_blacklist.actions | ||
|
||
- name: Commit and push changes | ||
run: | | ||
if [[ -n "$(git status --porcelain)" ]]; then | ||
git config user.name "github-actions[bot]" | ||
git config user.email "github-actions[bot]@users.noreply.github.com" | ||
git add . | ||
git ls-files | grep -i 'cookie' | xargs git reset # 排除 cookie | ||
git commit -m "automated update blacklist" --no-verify | ||
git push | ||
else | ||
echo "No changes to commit" | ||
fi | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
# DO NOT IMPORT THIS FILE FROM OTHER FILE | ||
import os | ||
import sys | ||
|
||
from .constant import BLACKLIST_DEST | ||
from .main import GamerAPIExtended | ||
from .utils import base64_decode, base64_encode, write_users | ||
|
||
cookie_path = "decoded_cookies.txt" | ||
|
||
|
||
def cookies_to_base64( | ||
input_file: str = "cookies.txt", | ||
output_file: str = "cookies_base64.txt", | ||
write: bool = False, | ||
) -> None | str: | ||
"""讀取 cookies 將內容進行 Base64 編碼後寫入或印出""" | ||
with open(input_file) as f: | ||
cookies_content = f.read() | ||
cookies_base64 = base64_encode(cookies_content) | ||
if write: | ||
with open(output_file, "w") as f: | ||
f.write(cookies_base64) | ||
else: | ||
return cookies_base64 | ||
|
||
|
||
def decode_cookies_from_base64(): | ||
"""從 GitHub 環境變數獲取 Base64 編碼的 cookie, 解碼並寫進臨時檔案""" | ||
cookies_base64 = os.getenv("COOKIES_BASE64") | ||
if not cookies_base64: | ||
raise ValueError("環境變數 COOKIES_BASE64 未設定或為空") | ||
|
||
cookies_content = base64_decode(cookies_base64) | ||
|
||
with open(cookie_path, "w") as f: | ||
f.write(cookies_content) | ||
|
||
|
||
if __name__ == "__main__": | ||
cookie_jar = decode_cookies_from_base64() | ||
|
||
username = os.environ["BAHA_USERNAME"] | ||
api = GamerAPIExtended(username, cookie_path) | ||
|
||
if not api.check_login(): | ||
print("登入失敗,請更新 Cookies") | ||
sys.exit(0) | ||
|
||
print("開始匯出黑名單...") | ||
existing_users = api.export_users(username) | ||
print(f"黑名單匯出成功, 總共匯出 {len(existing_users)} 個名單") | ||
write_users(BLACKLIST_DEST, existing_users) | ||
print("黑名單匯出結束\n") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# Github Action 用,獲取 base64 編碼的 cookies | ||
import pyperclip | ||
|
||
from baha_blacklist.actions import cookies_to_base64 | ||
|
||
pyperclip.copy(cookies_to_base64()) | ||
print("Base64 編碼的 Cookies 已複製到剪貼簿") |
Oops, something went wrong.