From c5c9eba41754325f5d6bda3cff00cb81e7a2b929 Mon Sep 17 00:00:00 2001 From: Tzu-Hua Lan Date: Wed, 31 Jul 2024 16:39:24 +0800 Subject: [PATCH 1/2] =?UTF-8?q?hotfix:=20=E6=8F=90=E4=BE=9B=E5=AF=AB?= =?UTF-8?q?=E6=AD=BB=20cookie=20=E7=9A=84=E7=99=BB=E5=85=A5=E6=96=B9?= =?UTF-8?q?=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .example.env | 7 ++++++- CHANGELOG.md | 5 +++++ main/lineClient.py | 24 ++++++++++++++++++++++-- 3 files changed, 33 insertions(+), 3 deletions(-) diff --git a/.example.env b/.example.env index 31e2b56..778bd2b 100644 --- a/.example.env +++ b/.example.env @@ -7,4 +7,9 @@ LINE_ACCOUNT_MID='Ue0d6270a7d8d1d0563b76f2e9f63fba0' # Firebase URL FIREBASE_URL='https://hiking-guard.firebaseio.com/' # 設定幾秒鐘後自動關閉,設為 0 表示無限 -SHUTDOWN_SECONDS=10 \ No newline at end of file +SHUTDOWN_SECONDS=10 + +# 是否以寫死的 cookie 來進行登入 +LOGIN_WITH_COOKIE=false +# Cookie Session +COOKIE_SES='' \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index 66d37fd..61595ba 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ # CHANGELOG +## 1.2.2-recaptcha.0 + +- (hotfix) 提供寫死 cookie 登入的方式 + 新增兩個 env 參數,`LOGIN_WITH_COOKIE` 和 `COOKIE_SES` + ## 1.2.2 - (fix) 更新 SSE loop 的程式邏輯,以避免無限死循環 diff --git a/main/lineClient.py b/main/lineClient.py index 9fed5c3..383fa65 100644 --- a/main/lineClient.py +++ b/main/lineClient.py @@ -24,7 +24,21 @@ def __init__(self): } self.session = requests.session() self.tempData = {} - self.loginWithEmail() + if os.environ["LOGIN_WITH_COOKIE"].lower() == "true": + self.loginWithHardcodeCookie() + else: + self.loginWithEmail() + + def loginWithHardcodeCookie(self): + self.session.cookies.set( + "ses", + os.environ["COOKIE_SES"], + ) + self.getCsrfToken() + chatList = self.getChatList(folderType="INBOX") + if "list" not in chatList: + sys.exit(f"Cookie Login Failed") + print("[ NOTIF ] Success login...") def loginWithEmail(self): """ @@ -71,7 +85,13 @@ def loginWithEmail(self): "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.183 Safari/537.36", "X-XSRF-TOKEN": csrfToken, }, - json={"email": self.email, "password": self.password, "stayLoggedIn": False}, + json={ + "email": self.email, + "password": self.password, + "stayLoggedIn": False, + # TODO: How to bypass reCAPTCHA? + "gRecaptchaResponse": "", + }, ) if loginResult.status_code != 200: From f2f3713e12b93d720f3d24a645c10ceadc472b8c Mon Sep 17 00:00:00 2001 From: Tzu-Hua Lan Date: Wed, 31 Jul 2024 16:44:36 +0800 Subject: [PATCH 2/2] release: 1.2.2-recaptcha.0 --- .github/workflows/build-image-and-deploy-to-gce.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build-image-and-deploy-to-gce.yaml b/.github/workflows/build-image-and-deploy-to-gce.yaml index c785e32..ac3ca73 100644 --- a/.github/workflows/build-image-and-deploy-to-gce.yaml +++ b/.github/workflows/build-image-and-deploy-to-gce.yaml @@ -11,7 +11,7 @@ on: env: # 聊天機器人的版本,每當升版時需要進行更新 - CHATBOT_VERSION: 1.2.2 + CHATBOT_VERSION: 1.2.2-recaptcha.0 # GCP Project ID(Artifact Registry 和 GCE 都在同一個 project) PROJECT_ID: hiking-guard