Spaces:
Running
Running
Commit ยท
a294a67
1
Parent(s): bf73759
no message
Browse files- app/app.py +18 -8
app/app.py
CHANGED
|
@@ -39,12 +39,12 @@ if not os.path.exists(credentials_path):
|
|
| 39 |
else:
|
| 40 |
print("๊ฒฝ๊ณ : .env ํ์ผ์ 'GOOGLE_CREDENTIALS_JSON' ๋ณ์๊ฐ ์์ต๋๋ค.")
|
| 41 |
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
|
| 49 |
|
| 50 |
CREDENTIALS_FILENAME = credentials_path
|
|
@@ -101,26 +101,34 @@ def get_oauth_credentials():
|
|
| 101 |
- token.json์ด ์์ผ๋ฉด ์ฌ์ฉํ๊ณ , ์๊ฑฐ๋ ๋ง๋ฃ๋์์ผ๋ฉด ์๋ก ์ธ์ฆํฉ๋๋ค.
|
| 102 |
"""
|
| 103 |
creds = None
|
|
|
|
| 104 |
# token.json ํ์ผ์ด ์ด๋ฏธ ์กด์ฌํ๋ฉด, ์ ์ฅ๋ ์ธ์ฆ ์ ๋ณด๋ฅผ ๋ถ๋ฌ์ต๋๋ค.
|
| 105 |
if os.path.exists(TOKEN_FILENAME):
|
|
|
|
| 106 |
creds = Credentials.from_authorized_user_file(TOKEN_FILENAME, SCOPES)
|
| 107 |
-
|
| 108 |
# ์ธ์ฆ ์ ๋ณด๊ฐ ์๊ฑฐ๋ ์ ํจํ์ง ์์ผ๋ฉด, ์ฌ์ฉ์์๊ฒ ๋ก๊ทธ์ธ์ ์์ฒญํฉ๋๋ค.
|
| 109 |
if not creds or not creds.valid:
|
|
|
|
| 110 |
if creds and creds.expired and creds.refresh_token:
|
|
|
|
| 111 |
# ํ ํฐ์ด ๋ง๋ฃ๋์์ผ๋ฉด, ๋ฆฌํ๋ ์ ํ ํฐ์ ์ฌ์ฉํด ๊ฐฑ์ ํฉ๋๋ค.
|
| 112 |
creds.refresh(GoogleRequest())
|
| 113 |
else:
|
|
|
|
| 114 |
# ํ ํฐ์ด ์์ผ๋ฉด, credentials.json์ ์ด์ฉํด ์๋ก์ด ์ธ์ฆ ์ ์ฐจ๋ฅผ ์์ํฉ๋๋ค.
|
| 115 |
flow = InstalledAppFlow.from_client_secrets_file(
|
| 116 |
CREDENTIALS_FILENAME, SCOPES)
|
|
|
|
| 117 |
# ์๋ฒ ํ๊ฒฝ์ ์ํด ๋ก์ปฌ ์๋ฒ ๋์ ์ฝ์ ๊ธฐ๋ฐ ์ธ์ฆ์ ์คํํฉ๋๋ค.
|
| 118 |
creds = flow.run_console()
|
| 119 |
|
| 120 |
# ๋ค์ ์คํ์ ์ํด ์๋ก ๋ฐ๊ธ๋ฐ๊ฑฐ๋ ๊ฐฑ์ ๋ ์ธ์ฆ ์ ๋ณด๋ฅผ token.json ํ์ผ์ ์ ์ฅํฉ๋๋ค.
|
|
|
|
| 121 |
with open(TOKEN_FILENAME, 'w') as token:
|
|
|
|
| 122 |
token.write(creds.to_json())
|
| 123 |
-
|
| 124 |
return creds
|
| 125 |
|
| 126 |
|
|
@@ -368,3 +376,5 @@ async def handle_chatwork_webhook(
|
|
| 368 |
|
| 369 |
# Chatwork์ ์ฑ๊ณต์ ์ผ๋ก ์์ ํ์์ ์๋ฆผ
|
| 370 |
return {"status": "success"}
|
|
|
|
|
|
|
|
|
| 39 |
else:
|
| 40 |
print("๊ฒฝ๊ณ : .env ํ์ผ์ 'GOOGLE_CREDENTIALS_JSON' ๋ณ์๊ฐ ์์ต๋๋ค.")
|
| 41 |
|
| 42 |
+
if not os.path.exists(token_path):
|
| 43 |
+
print(f"'{token_path}' ํ์ผ์ด ์์ด ์๋ก ์์ฑํฉ๋๋ค.")
|
| 44 |
+
token_str = os.getenv('GOOGLE_TOKEN_JSON')
|
| 45 |
+
if token_str:
|
| 46 |
+
with open(token_path, 'w', encoding='utf-8') as f:
|
| 47 |
+
f.write(token_str)
|
| 48 |
|
| 49 |
|
| 50 |
CREDENTIALS_FILENAME = credentials_path
|
|
|
|
| 101 |
- token.json์ด ์์ผ๋ฉด ์ฌ์ฉํ๊ณ , ์๊ฑฐ๋ ๋ง๋ฃ๋์์ผ๋ฉด ์๋ก ์ธ์ฆํฉ๋๋ค.
|
| 102 |
"""
|
| 103 |
creds = None
|
| 104 |
+
print(f"log1")
|
| 105 |
# token.json ํ์ผ์ด ์ด๋ฏธ ์กด์ฌํ๋ฉด, ์ ์ฅ๋ ์ธ์ฆ ์ ๋ณด๋ฅผ ๋ถ๋ฌ์ต๋๋ค.
|
| 106 |
if os.path.exists(TOKEN_FILENAME):
|
| 107 |
+
print(f"log2")
|
| 108 |
creds = Credentials.from_authorized_user_file(TOKEN_FILENAME, SCOPES)
|
| 109 |
+
print(f"log3")
|
| 110 |
# ์ธ์ฆ ์ ๋ณด๊ฐ ์๊ฑฐ๋ ์ ํจํ์ง ์์ผ๋ฉด, ์ฌ์ฉ์์๊ฒ ๋ก๊ทธ์ธ์ ์์ฒญํฉ๋๋ค.
|
| 111 |
if not creds or not creds.valid:
|
| 112 |
+
print(f"log4")
|
| 113 |
if creds and creds.expired and creds.refresh_token:
|
| 114 |
+
print(f"log5")
|
| 115 |
# ํ ํฐ์ด ๋ง๋ฃ๋์์ผ๋ฉด, ๋ฆฌํ๋ ์ ํ ํฐ์ ์ฌ์ฉํด ๊ฐฑ์ ํฉ๋๋ค.
|
| 116 |
creds.refresh(GoogleRequest())
|
| 117 |
else:
|
| 118 |
+
print(f"log6")
|
| 119 |
# ํ ํฐ์ด ์์ผ๋ฉด, credentials.json์ ์ด์ฉํด ์๋ก์ด ์ธ์ฆ ์ ์ฐจ๋ฅผ ์์ํฉ๋๋ค.
|
| 120 |
flow = InstalledAppFlow.from_client_secrets_file(
|
| 121 |
CREDENTIALS_FILENAME, SCOPES)
|
| 122 |
+
print(f"log7")
|
| 123 |
# ์๋ฒ ํ๊ฒฝ์ ์ํด ๋ก์ปฌ ์๋ฒ ๋์ ์ฝ์ ๊ธฐ๋ฐ ์ธ์ฆ์ ์คํํฉ๋๋ค.
|
| 124 |
creds = flow.run_console()
|
| 125 |
|
| 126 |
# ๋ค์ ์คํ์ ์ํด ์๋ก ๋ฐ๊ธ๋ฐ๊ฑฐ๋ ๊ฐฑ์ ๋ ์ธ์ฆ ์ ๋ณด๋ฅผ token.json ํ์ผ์ ์ ์ฅํฉ๋๋ค.
|
| 127 |
+
print(f"log8")
|
| 128 |
with open(TOKEN_FILENAME, 'w') as token:
|
| 129 |
+
print(f"log9")
|
| 130 |
token.write(creds.to_json())
|
| 131 |
+
print(f"log10")
|
| 132 |
return creds
|
| 133 |
|
| 134 |
|
|
|
|
| 376 |
|
| 377 |
# Chatwork์ ์ฑ๊ณต์ ์ผ๋ก ์์ ํ์์ ์๋ฆผ
|
| 378 |
return {"status": "success"}
|
| 379 |
+
|
| 380 |
+
get_oauth_credentials()
|