Skip to content
This repository has been archived by the owner on Sep 18, 2024. It is now read-only.

Commit

Permalink
Merge pull request #26 from blueBlue0102/release
Browse files Browse the repository at this point in the history
Release
  • Loading branch information
blueBlue0102 authored Jul 31, 2024
2 parents 75a5686 + f2f3713 commit 82689c1
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 4 deletions.
7 changes: 6 additions & 1 deletion .example.env
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,9 @@ LINE_ACCOUNT_MID='Ue0d6270a7d8d1d0563b76f2e9f63fba0'
# Firebase URL
FIREBASE_URL='https://hiking-guard.firebaseio.com/'
# 設定幾秒鐘後自動關閉,設為 0 表示無限
SHUTDOWN_SECONDS=10
SHUTDOWN_SECONDS=10

# 是否以寫死的 cookie 來進行登入
LOGIN_WITH_COOKIE=false
# Cookie Session
COOKIE_SES=''
2 changes: 1 addition & 1 deletion .github/workflows/build-image-and-deploy-to-gce.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# CHANGELOG

## 1.2.2-recaptcha.0

- (hotfix) 提供寫死 cookie 登入的方式
新增兩個 env 參數,`LOGIN_WITH_COOKIE``COOKIE_SES`

## 1.2.2

- (fix) 更新 SSE loop 的程式邏輯,以避免無限死循環
Expand Down
24 changes: 22 additions & 2 deletions main/lineClient.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
"""
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit 82689c1

Please sign in to comment.