Update apps/saju.py
Browse files- apps/saju.py +44 -5
apps/saju.py
CHANGED
|
@@ -1,5 +1,7 @@
|
|
| 1 |
import os
|
| 2 |
import requests
|
|
|
|
|
|
|
| 3 |
from datetime import datetime, timedelta
|
| 4 |
from typing import Union
|
| 5 |
from fastapi import APIRouter, Request
|
|
@@ -67,19 +69,19 @@ def analyze_saju(req: SajuRequest):
|
|
| 67 |
1. **์ค์: ๋ชจ๋ ๊ฐ์กฐ(Bold) ์ฒ๋ฆฌ๋ ๋งํฌ๋ค์ด(**)์ด ์๋ HTML `<b>` ํ๊ทธ๋ฅผ ์ฌ์ฉํ์ธ์.**
|
| 68 |
2. ์ธ์ฌ๋ง: ๋ฐ๋์ `<div class="greeting">` ํ๊ทธ๋ก ๊ฐ์ธ์ ์์ฑํ์ธ์.
|
| 69 |
3. ์๊ฐ ์๋ต: ์๊ธฐ์๊ฐ๋ ํ์ง ๋ง์ธ์.
|
| 70 |
-
4. ํ์: ๋ชจ๋ ์น์
('์ค๋์ ์ฌ์ฃผ ๋ถ์', '์ค๋์ ํ์ด ์ปฌ๋ฌ', '์ค๋์ ์ถ์ฒ ์ฝ๋', '์ค๋์ ๋ง์โผผ๊ฐ์ง')์ <details><summary>... [๋ณด๊ธฐ]</summary></details> ํ๊ทธ๋ก ๊ฐ์ธ์ ์ ์ด๋์ธ์.
|
| 71 |
-
5.
|
|
|
|
|
|
|
| 72 |
"""
|
| 73 |
|
| 74 |
last_error = None
|
| 75 |
|
| 76 |
-
# [์์ 2] api_keys -> GEMINI_API_KEYS ๋ก ๋ณ์๋ช
์์
|
| 77 |
if not GEMINI_API_KEYS:
|
| 78 |
return JSONResponse(content={'result': "<div class='greeting'>์๋ฒ์ API ํค๊ฐ ์ค์ ๋์ง ์์์ต๋๋ค.</div>"})
|
| 79 |
|
| 80 |
send_slack_message(f"๐ฎ [Theo] ๋ถ์ ์์ฒญ: {birth_info}")
|
| 81 |
|
| 82 |
-
# [์์ 3] api_keys -> GEMINI_API_KEYS ๋ก ๋ณ์๋ช
์์
|
| 83 |
for key_idx, current_key in enumerate(GEMINI_API_KEYS):
|
| 84 |
key_alias = f"KEY_{key_idx+1}"
|
| 85 |
|
|
@@ -97,13 +99,50 @@ def analyze_saju(req: SajuRequest):
|
|
| 97 |
|
| 98 |
if response.text:
|
| 99 |
send_slack_message(f"โ
[์ฑ๊ณต] {key_alias} / {model_name}")
|
| 100 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 101 |
|
| 102 |
except Exception as e:
|
| 103 |
last_error = e
|
| 104 |
continue
|
| 105 |
|
| 106 |
error_msg = str(last_error)
|
|
|
|
| 107 |
send_slack_message(f"๐จ [์ ์ฒด ์คํจ] ์๋ฌ: {error_msg}")
|
| 108 |
|
| 109 |
return JSONResponse(content={
|
|
|
|
| 1 |
import os
|
| 2 |
import requests
|
| 3 |
+
import re # ์ ๊ท์ ํ์ฑ์ฉ
|
| 4 |
+
import random
|
| 5 |
from datetime import datetime, timedelta
|
| 6 |
from typing import Union
|
| 7 |
from fastapi import APIRouter, Request
|
|
|
|
| 69 |
1. **์ค์: ๋ชจ๋ ๊ฐ์กฐ(Bold) ์ฒ๋ฆฌ๋ ๋งํฌ๋ค์ด(**)์ด ์๋ HTML `<b>` ํ๊ทธ๋ฅผ ์ฌ์ฉํ์ธ์.**
|
| 70 |
2. ์ธ์ฌ๋ง: ๋ฐ๋์ `<div class="greeting">` ํ๊ทธ๋ก ๊ฐ์ธ์ ์์ฑํ์ธ์.
|
| 71 |
3. ์๊ฐ ์๋ต: ์๊ธฐ์๊ฐ๋ ํ์ง ๋ง์ธ์.
|
| 72 |
+
4. ํ์: ๋ชจ๋ ์น์
('์ค๋์ ์ฌ์ฃผ ๋ถ์', '์ค๋์ ํ์ด ์ปฌ๋ฌ', '์ค๋์ ํ์ด ๋ฒํธ', '์ค๋์ ์ถ์ฒ ์ฝ๋', '์ค๋์ ๋ง์โผผ๊ฐ์ง')์ <details><summary>... [๋ณด๊ธฐ]</summary></details> ํ๊ทธ๋ก ๊ฐ์ธ์ ์ ์ด๋์ธ์.
|
| 73 |
+
5. **(ํ์)** '์ค๋์ ํ์ด ๋ฒํธ' ์น์
์ ์ถ๊ฐํ์ฌ 1๋ถํฐ 45 ์ฌ์ด์ ๊ฒน์น์ง ์๋ ์ซ์ 6๊ฐ๋ฅผ ์ถ์ฒํด ์ฃผ์ธ์.
|
| 74 |
+
6. **(์์คํ
ํ์ฑ์ฉ - ๋งค์ฐ ์ค์)** ๋ฐฑ์๋ ์์คํ
ํ์ฑ์ ์ํด ์๋ต ํ
์คํธ ๋งจ ๋ง์ง๋ง ์ค์ ๋ฐ๋์ ์๋์ ๊ฐ์ ํ์์ HTML ์ฃผ์์ ์ถ๊ฐํ์ธ์. (์ซ์๋ ์ผํ๋ก ๊ตฌ๋ถ)
|
| 75 |
+
7. ํค์ค๋งค๋: ์ ๋ฌธ์ ์ด๊ณ ์ฐ์ํ ์ด์กฐ.
|
| 76 |
"""
|
| 77 |
|
| 78 |
last_error = None
|
| 79 |
|
|
|
|
| 80 |
if not GEMINI_API_KEYS:
|
| 81 |
return JSONResponse(content={'result': "<div class='greeting'>์๋ฒ์ API ํค๊ฐ ์ค์ ๋์ง ์์์ต๋๋ค.</div>"})
|
| 82 |
|
| 83 |
send_slack_message(f"๐ฎ [Theo] ๋ถ์ ์์ฒญ: {birth_info}")
|
| 84 |
|
|
|
|
| 85 |
for key_idx, current_key in enumerate(GEMINI_API_KEYS):
|
| 86 |
key_alias = f"KEY_{key_idx+1}"
|
| 87 |
|
|
|
|
| 99 |
|
| 100 |
if response.text:
|
| 101 |
send_slack_message(f"โ
[์ฑ๊ณต] {key_alias} / {model_name}")
|
| 102 |
+
|
| 103 |
+
# ==========================================
|
| 104 |
+
# ๐จ [์ถ๊ฐ๋ ๋ก์ง] ํ์ด ๋ฒํธ ์ถ์ถ (ํ์ฑ)
|
| 105 |
+
# ==========================================
|
| 106 |
+
text_result = response.text
|
| 107 |
+
lucky_numbers = []
|
| 108 |
+
|
| 109 |
+
# ์ ๋ฏธ๋์ด๊ฐ ์จ๊ฒจ๋ ์ฃผ์()์์ ๋ฒํธ๋ง ๋นผ์ค๊ธฐ
|
| 110 |
+
match = re.search(r'', text_result)
|
| 111 |
+
if match:
|
| 112 |
+
try:
|
| 113 |
+
num_str = match.group(1)
|
| 114 |
+
# "7, 14, 21" ๋ฌธ์๋ฅผ ์ซ์ ๋ฆฌ์คํธ [7, 14, 21]๋ก ๋ณํ ๋ฐ 1~45 ๋ฒ์ ์ฒดํฌ
|
| 115 |
+
lucky_numbers = [int(n.strip()) for n in num_str.split(',') if n.strip().isdigit()]
|
| 116 |
+
lucky_numbers = [n for n in lucky_numbers if 1 <= n <= 45]
|
| 117 |
+
lucky_numbers = list(set(lucky_numbers)) # ์ค๋ณต ์ ๊ฑฐ
|
| 118 |
+
except Exception:
|
| 119 |
+
pass
|
| 120 |
+
|
| 121 |
+
# ๐ก [์์ ์ฅ์น] ์ ๋ฏธ๋์ด๊ฐ ์ค์๋ก ๋ฒํธ๋ฅผ ์ ์คฌ๊ฑฐ๋ 6๊ฐ๊ฐ ์ ๋ ๊ฒฝ์ฐ,
|
| 122 |
+
# ๋น์๋ฆฌ๋ ํ์ด์ฌ์ด ์์์ ๋ฌด์์ ํ์ด๋ฒํธ๋ก ์ฑ์์ค๋๋ค! (์๋ฌ ๋ฐฉ์ง)
|
| 123 |
+
while len(lucky_numbers) < 6:
|
| 124 |
+
rand_num = random.randint(1, 45)
|
| 125 |
+
if rand_num not in lucky_numbers:
|
| 126 |
+
lucky_numbers.append(rand_num)
|
| 127 |
+
|
| 128 |
+
# ๋ฑ 6๊ฐ๋ง ์๋ฅด๊ณ ์ค๋ฆ์ฐจ์ ์ ๋ ฌ
|
| 129 |
+
lucky_numbers = lucky_numbers[:6]
|
| 130 |
+
lucky_numbers.sort()
|
| 131 |
+
|
| 132 |
+
# ==========================================
|
| 133 |
+
# ํ๋ก ํธ์๋๋ก ํ
์คํธ๋ฅผ ๋๊ธฐ๊ธฐ ์ ์ ์ฃผ์()์ ์์ ์ง์๋ฒ๋ฆผ!
|
| 134 |
+
text_result = re.sub(r'', '', text_result).strip()
|
| 135 |
+
# ==========================================
|
| 136 |
+
|
| 137 |
+
# ํ๋ก ํธ์๋(main_saju.html)์์ ์ฝ์ํ๋ luckyNumbers ํค๊ฐ์ผ๋ก ์ด์ค๋๋ค!
|
| 138 |
+
return {"result": text_result, "luckyNumbers": lucky_numbers}
|
| 139 |
|
| 140 |
except Exception as e:
|
| 141 |
last_error = e
|
| 142 |
continue
|
| 143 |
|
| 144 |
error_msg = str(last_error)
|
| 145 |
+
|
| 146 |
send_slack_message(f"๐จ [์ ์ฒด ์คํจ] ์๋ฌ: {error_msg}")
|
| 147 |
|
| 148 |
return JSONResponse(content={
|