Update src/app.py
Browse files- src/app.py +207 -212
src/app.py
CHANGED
|
@@ -1167,7 +1167,7 @@ def _build_alert_groups(prices, rate):
|
|
| 1167 |
|
| 1168 |
for _, row in st.session_state.df.iterrows():
|
| 1169 |
t = row['ν°μ»€']
|
| 1170 |
-
ap = row['νλ¨κ°']
|
| 1171 |
nm = row['μ’
λͺ©λͺ
']
|
| 1172 |
ck = prices.get(t, 0) * rate
|
| 1173 |
if ck <= 0 or ap <= 0:
|
|
@@ -1217,16 +1217,7 @@ def _navigate_to_ticker(ticker, from_portfolio=True):
|
|
| 1217 |
|
| 1218 |
|
| 1219 |
def render_grouped_alert_panel(prices, rate):
|
| 1220 |
-
"""μ°νλ¨ νλ‘ν
μλ ν¨λ β components.html
|
| 1221 |
-
import streamlit.components.v1 as components
|
| 1222 |
-
|
| 1223 |
-
TAB_CFG = {
|
| 1224 |
-
"κΈλ³": {"icon": "β‘", "accent": "#FF6B35", "bg": "rgba(255,107,53,0.12)", "border": "rgba(255,107,53,0.35)"},
|
| 1225 |
-
"λ§€μ": {"icon": "π", "accent": "#00D4AA", "bg": "rgba(0,212,170,0.12)", "border": "rgba(0,212,170,0.35)"},
|
| 1226 |
-
"μ΅μ ": {"icon": "β
", "accent": "#4299E1", "bg": "rgba(66,153,225,0.12)", "border": "rgba(66,153,225,0.35)"},
|
| 1227 |
-
"μ€ν±λ‘μ€": {"icon": "π", "accent": "#E53E3E", "bg": "rgba(229,62,62,0.12)", "border": "rgba(229,62,62,0.35)"},
|
| 1228 |
-
}
|
| 1229 |
-
|
| 1230 |
groups = _build_alert_groups(prices, rate)
|
| 1231 |
total_cnt = sum(len(v) for v in groups.values())
|
| 1232 |
if total_cnt == 0:
|
|
@@ -1237,10 +1228,16 @@ def render_grouped_alert_panel(prices, rate):
|
|
| 1237 |
if time_left == 0 and not st.session_state.alert_panel_minimized:
|
| 1238 |
st.session_state.alert_panel_minimized = True
|
| 1239 |
|
| 1240 |
-
|
| 1241 |
-
|
| 1242 |
-
|
| 1243 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1244 |
|
| 1245 |
if st.session_state.alert_active_tab not in TAB_CFG:
|
| 1246 |
for pt in ["μ€ν±λ‘μ€", "κΈλ³", "μ΅μ ", "λ§€μ"]:
|
|
@@ -1248,211 +1245,209 @@ def render_grouped_alert_panel(prices, rate):
|
|
| 1248 |
else: st.session_state.alert_active_tab = "κΈλ³"
|
| 1249 |
active_tab = st.session_state.alert_active_tab
|
| 1250 |
|
| 1251 |
-
|
| 1252 |
-
|
| 1253 |
-
items = groups[tab]
|
| 1254 |
-
if not items:
|
| 1255 |
-
return '<p style="text-align:center;padding:20px;color:rgba(255,255,255,0.2);font-size:13px;margin:0;">μλ μμ</p>'
|
| 1256 |
-
rows = ""
|
| 1257 |
-
for item in items:
|
| 1258 |
-
pct = item["change_pct"]
|
| 1259 |
-
sign = "▲" if pct >= 0 else "▼"
|
| 1260 |
-
ps = sign + " " + str(round(abs(pct), 1)) + "%"
|
| 1261 |
-
tick = item["ticker"]
|
| 1262 |
-
nm = (item["name"][:14] + "..") if len(item["name"]) > 14 else item["name"]
|
| 1263 |
-
cp = format(item["current_price"], ",") + "원"
|
| 1264 |
-
rows += (
|
| 1265 |
-
'<div onclick="goTo(\'' + tick + '\')" '
|
| 1266 |
-
'style="display:flex;align-items:center;gap:10px;padding:9px 11px;'
|
| 1267 |
-
'border-radius:9px;cursor:pointer;margin-bottom:3px;background:rgba(255,255,255,0.02);" '
|
| 1268 |
-
'onmouseover="this.style.background=\'rgba(255,255,255,0.07)\'" '
|
| 1269 |
-
'onmouseout="this.style.background=\'rgba(255,255,255,0.02)\'">'
|
| 1270 |
-
'<div style="width:38px;height:38px;border-radius:8px;flex-shrink:0;'
|
| 1271 |
-
'background:' + tc["bg"] + ';border:1px solid ' + tc["border"] + ';'
|
| 1272 |
-
'display:flex;align-items:center;justify-content:center;'
|
| 1273 |
-
'font-size:9px;font-weight:800;color:' + tc["accent"] + ';">' + tick[:4] + '</div>'
|
| 1274 |
-
'<div style="flex:1;min-width:0;">'
|
| 1275 |
-
'<div style="font-size:12px;font-weight:700;color:#eef2f7;">' + tick +
|
| 1276 |
-
' <span style="font-size:10px;color:rgba(255,255,255,0.3);">' + nm + '</span></div>'
|
| 1277 |
-
'<div style="font-size:11px;color:rgba(255,255,255,0.3);">' + cp + '</div>'
|
| 1278 |
-
'</div>'
|
| 1279 |
-
'<div style="text-align:right;flex-shrink:0;">'
|
| 1280 |
-
'<div style="font-size:12px;font-weight:700;color:' + tc["accent"] + ';">' + ps + '</div>'
|
| 1281 |
-
'<div style="font-size:10px;color:rgba(255,255,255,0.2);">→ 분석</div>'
|
| 1282 |
-
'</div></div>'
|
| 1283 |
-
)
|
| 1284 |
-
return rows
|
| 1285 |
-
|
| 1286 |
-
all_items = {tab: make_items(tab) for tab in TAB_CFG}
|
| 1287 |
-
|
| 1288 |
-
tabs_html = ""
|
| 1289 |
for tab, tc in TAB_CFG.items():
|
| 1290 |
-
|
| 1291 |
-
|
| 1292 |
-
|
| 1293 |
-
|
| 1294 |
-
|
| 1295 |
-
|
| 1296 |
-
|
| 1297 |
-
|
| 1298 |
-
|
| 1299 |
-
|
| 1300 |
-
|
| 1301 |
-
|
| 1302 |
-
|
| 1303 |
-
|
| 1304 |
-
|
| 1305 |
-
|
| 1306 |
-
|
| 1307 |
-
|
| 1308 |
-
)
|
| 1309 |
-
|
| 1310 |
-
items_json = json.dumps(all_items, ensure_ascii=False)
|
| 1311 |
-
init_min = "true" if minimized else "false"
|
| 1312 |
-
|
| 1313 |
-
html = (
|
| 1314 |
-
"<!DOCTYPE html><html><head><meta charset='utf-8'>"
|
| 1315 |
-
"<style>"
|
| 1316 |
-
"* { margin:0; padding:0; box-sizing:border-box; font-family:'Noto Sans KR',sans-serif; }"
|
| 1317 |
-
"html, body { background:transparent; overflow:hidden; width:100%; height:100%; }"
|
| 1318 |
-
"@keyframes apP { 0%,100%{opacity:1} 50%{opacity:.3} }"
|
| 1319 |
-
"@keyframes apS { from{transform:translateY(14px);opacity:0} to{transform:none;opacity:1} }"
|
| 1320 |
-
"@keyframes apB { from{transform:scale(.7);opacity:0} to{transform:none;opacity:1} }"
|
| 1321 |
-
"#panel {"
|
| 1322 |
-
"position:fixed; bottom:4px; right:4px;"
|
| 1323 |
-
"width:356px;"
|
| 1324 |
-
"z-index:9999;"
|
| 1325 |
-
"animation:apS .35s cubic-bezier(.34,1.56,.64,1);"
|
| 1326 |
-
"}"
|
| 1327 |
-
"#badge {"
|
| 1328 |
-
"position:fixed; bottom:4px; right:4px;"
|
| 1329 |
-
"display:flex; align-items:center; gap:8px;"
|
| 1330 |
-
"background:linear-gradient(135deg,#1a2035,#131820);"
|
| 1331 |
-
"border:1px solid " + badge_color + "; border-radius:40px;"
|
| 1332 |
-
"padding:9px 18px; cursor:pointer; z-index:9999;"
|
| 1333 |
-
"box-shadow:0 6px 24px rgba(0,0,0,.6);"
|
| 1334 |
-
"animation:apB .35s cubic-bezier(.34,1.56,.64,1);"
|
| 1335 |
-
"}"
|
| 1336 |
-
"#badge:hover { border-color:#fff; }"
|
| 1337 |
-
".body { max-height:240px; overflow-y:auto; padding:6px; }"
|
| 1338 |
-
".body::-webkit-scrollbar { width:3px; }"
|
| 1339 |
-
".body::-webkit-scrollbar-thumb { background:rgba(255,255,255,.15); border-radius:3px; }"
|
| 1340 |
-
"</style></head><body>"
|
| 1341 |
-
|
| 1342 |
-
# λ°°μ§
|
| 1343 |
-
"<div id='badge' style='display:" + ("flex" if minimized else "none") + ";'>"
|
| 1344 |
-
"<span style='font-size:18px;position:relative;line-height:1;'>🔔"
|
| 1345 |
-
"<span style='position:absolute;top:-5px;right:-8px;background:" + badge_color + ";color:#fff;"
|
| 1346 |
-
"border-radius:10px;font-size:9px;font-weight:700;min-width:16px;height:16px;"
|
| 1347 |
-
"display:flex;align-items:center;justify-content:center;padding:0 3px;'>" + str(total_cnt) + "</span>"
|
| 1348 |
-
"</span>"
|
| 1349 |
-
"<span style='font-size:12px;font-weight:700;color:#e8eaf0;'>알람 " + str(total_cnt) + "개</span>"
|
| 1350 |
-
"<span style='width:6px;height:6px;border-radius:50%;background:" + badge_color + ";"
|
| 1351 |
-
"animation:apP 1.5s infinite;display:inline-block;'></span>"
|
| 1352 |
-
"</div>"
|
| 1353 |
-
|
| 1354 |
-
# ν¨λ
|
| 1355 |
-
"<div id='panel' style='display:" + ("none" if minimized else "block") + ";'>"
|
| 1356 |
-
"<div style='background:linear-gradient(135deg,#1a2035,#131820);"
|
| 1357 |
-
"border:1px solid rgba(255,255,255,.09);border-bottom:none;border-radius:14px 14px 0 0;padding:12px 14px 0;'>"
|
| 1358 |
-
"<div style='display:flex;align-items:center;justify-content:space-between;margin-bottom:10px;'>"
|
| 1359 |
-
"<div style='display:flex;align-items:center;gap:7px;'>"
|
| 1360 |
-
"<div style='width:7px;height:7px;border-radius:50%;background:#FF6B35;animation:apP 1.5s infinite;'></div>"
|
| 1361 |
-
"<span style='color:#eef2f7;font-size:12px;font-weight:700;letter-spacing:.06em;'>LIVE ALERTS</span>"
|
| 1362 |
-
"<span style='background:rgba(229,62,62,.15);border:1px solid rgba(229,62,62,.3);"
|
| 1363 |
-
"border-radius:5px;padding:1px 7px;font-size:10px;color:#E53E3E;font-weight:700;'>" + str(total_cnt) + "</span>"
|
| 1364 |
-
"</div>"
|
| 1365 |
-
"<div style='background:rgba(255,255,255,.05);border-radius:7px;padding:3px 9px;"
|
| 1366 |
-
"display:flex;align-items:center;gap:4px;'>"
|
| 1367 |
-
"<span>⏱</span>"
|
| 1368 |
-
"<span id='timer' style='font-size:11px;font-weight:700;font-family:DM Mono,monospace;color:" + timer_col + ";'>" + str(time_left) + "s</span>"
|
| 1369 |
-
"</div>"
|
| 1370 |
-
"</div>"
|
| 1371 |
-
"<div style='display:flex;gap:3px;'>" + tabs_html + "</div>"
|
| 1372 |
-
"</div>"
|
| 1373 |
-
"<div class='body' style='background:linear-gradient(180deg,#161c2a,#111620);"
|
| 1374 |
-
"border:1px solid rgba(255,255,255,.09);border-radius:0 0 14px 14px;' id='body'>"
|
| 1375 |
-
+ all_items[active_tab] +
|
| 1376 |
-
"</div>"
|
| 1377 |
-
"<button onclick='minimize()' style='width:100%;margin-top:4px;padding:6px;"
|
| 1378 |
-
"background:rgba(255,255,255,.04);border:1px solid rgba(255,255,255,.08);"
|
| 1379 |
-
"border-radius:8px;color:rgba(255,255,255,.4);font-size:11px;cursor:pointer;'>− 최소화</button>"
|
| 1380 |
-
"</div>"
|
| 1381 |
-
|
| 1382 |
-
"<script>"
|
| 1383 |
-
"var M=" + init_min + ", T=" + str(time_left) + ", TAB=" + json.dumps(active_tab) + ";"
|
| 1384 |
-
"var DATA=" + items_json + ";"
|
| 1385 |
-
"var te=document.getElementById('timer');"
|
| 1386 |
-
|
| 1387 |
-
"var iv=setInterval(function(){"
|
| 1388 |
-
"if(M)return; T--;"
|
| 1389 |
-
"if(T<=0){clearInterval(iv);minimize();send('expired');return;}"
|
| 1390 |
-
"if(te){te.textContent=T+'s';"
|
| 1391 |
-
"te.style.color=T<=15?'#E53E3E':T<=30?'#EAB308':'#8B98B4';}"
|
| 1392 |
-
"},1000);"
|
| 1393 |
-
|
| 1394 |
-
"function send(a){"
|
| 1395 |
-
"window.parent.postMessage({type:'alert_action',action:a},'*');"
|
| 1396 |
-
"}"
|
| 1397 |
-
"function minimize(){"
|
| 1398 |
-
"M=true;"
|
| 1399 |
-
"document.getElementById('panel').style.display='none';"
|
| 1400 |
-
"document.getElementById('badge').style.display='flex';"
|
| 1401 |
-
"send('minimize');"
|
| 1402 |
-
"}"
|
| 1403 |
-
"function openPanel(){"
|
| 1404 |
-
"M=false; T=" + str(time_left) + ";"
|
| 1405 |
-
"if(te)te.textContent=T+'s';"
|
| 1406 |
-
"document.getElementById('badge').style.display='none';"
|
| 1407 |
-
"document.getElementById('panel').style.display='block';"
|
| 1408 |
-
"send('open');"
|
| 1409 |
-
"}"
|
| 1410 |
-
"function switchTab(t){"
|
| 1411 |
-
"TAB=t;"
|
| 1412 |
-
"document.getElementById('body').innerHTML=DATA[t];"
|
| 1413 |
-
"send('tab:'+t);"
|
| 1414 |
-
"}"
|
| 1415 |
-
"function goTo(tk){ send('goto:'+tk); }"
|
| 1416 |
-
"document.getElementById('badge').onclick=openPanel;"
|
| 1417 |
-
"</script>"
|
| 1418 |
-
"</body></html>"
|
| 1419 |
-
)
|
| 1420 |
-
|
| 1421 |
-
# CSSλ‘ components.html iframeμ fixed μ€λ²λ μ΄λ‘ λ³ν
|
| 1422 |
st.markdown("""
|
| 1423 |
<style>
|
| 1424 |
-
/* components.html iframe β μ°νλ¨ κ³ μ μ€λ²λ μ΄ */
|
| 1425 |
-
[data-testid="stCustomComponentV1"] iframe,
|
| 1426 |
iframe[title="components.v1.html"] {
|
| 1427 |
position: fixed !important;
|
| 1428 |
-
|
| 1429 |
-
|
| 1430 |
-
|
| 1431 |
-
|
| 1432 |
-
|
| 1433 |
-
|
| 1434 |
-
|
| 1435 |
-
|
| 1436 |
-
|
| 1437 |
-
|
| 1438 |
-
|
| 1439 |
-
|
| 1440 |
-
|
| 1441 |
-
|
| 1442 |
-
|
| 1443 |
-
|
| 1444 |
-
""
|
| 1445 |
-
|
| 1446 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1447 |
st.markdown("""
|
| 1448 |
<script>
|
| 1449 |
-
window.addEventListener('message', function(e)
|
| 1450 |
-
|
| 1451 |
-
|
| 1452 |
-
|
| 1453 |
});
|
| 1454 |
-
</script>
|
| 1455 |
-
""", unsafe_allow_html=True)
|
| 1456 |
|
| 1457 |
components.html(html, height=0, scrolling=False)
|
| 1458 |
|
|
|
|
| 1167 |
|
| 1168 |
for _, row in st.session_state.df.iterrows():
|
| 1169 |
t = row['ν°μ»€']
|
| 1170 |
+
ap = float(row['νλ¨κ°'])
|
| 1171 |
nm = row['μ’
λͺ©λͺ
']
|
| 1172 |
ck = prices.get(t, 0) * rate
|
| 1173 |
if ck <= 0 or ap <= 0:
|
|
|
|
| 1217 |
|
| 1218 |
|
| 1219 |
def render_grouped_alert_panel(prices, rate):
|
| 1220 |
+
"""μ°νλ¨ νλ‘ν
μλ ν¨λ β components.html + CSS fixed overlay"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1221 |
groups = _build_alert_groups(prices, rate)
|
| 1222 |
total_cnt = sum(len(v) for v in groups.values())
|
| 1223 |
if total_cnt == 0:
|
|
|
|
| 1228 |
if time_left == 0 and not st.session_state.alert_panel_minimized:
|
| 1229 |
st.session_state.alert_panel_minimized = True
|
| 1230 |
|
| 1231 |
+
TAB_CFG = {
|
| 1232 |
+
"κΈλ³": {"icon": "β‘", "accent": "#FF6B35", "bg": "rgba(255,107,53,0.10)", "border": "rgba(255,107,53,0.30)"},
|
| 1233 |
+
"λ§€μ": {"icon": "π", "accent": "#00D4AA", "bg": "rgba(0,212,170,0.10)", "border": "rgba(0,212,170,0.30)"},
|
| 1234 |
+
"μ΅μ ": {"icon": "β
", "accent": "#4299E1", "bg": "rgba(66,153,225,0.10)", "border": "rgba(66,153,225,0.30)"},
|
| 1235 |
+
"μ€ν±λ‘μ€": {"icon": "π", "accent": "#E53E3E", "bg": "rgba(229,62,62,0.10)", "border": "rgba(229,62,62,0.30)"},
|
| 1236 |
+
}
|
| 1237 |
+
|
| 1238 |
+
sl_cnt = len(groups["μ€ν±λ‘μ€"])
|
| 1239 |
+
badge_col = "#E53E3E" if sl_cnt > 0 else "#FF6B35"
|
| 1240 |
+
minimized = st.session_state.alert_panel_minimized
|
| 1241 |
|
| 1242 |
if st.session_state.alert_active_tab not in TAB_CFG:
|
| 1243 |
for pt in ["μ€ν±λ‘μ€", "κΈλ³", "μ΅μ ", "λ§€μ"]:
|
|
|
|
| 1245 |
else: st.session_state.alert_active_tab = "κΈλ³"
|
| 1246 |
active_tab = st.session_state.alert_active_tab
|
| 1247 |
|
| 1248 |
+
# μ’
λͺ© λ°μ΄ν° JSON μ§λ ¬ν
|
| 1249 |
+
data = {}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1250 |
for tab, tc in TAB_CFG.items():
|
| 1251 |
+
rows = []
|
| 1252 |
+
for item in groups[tab]:
|
| 1253 |
+
pct = item["change_pct"]
|
| 1254 |
+
rows.append({
|
| 1255 |
+
"ticker": item["ticker"],
|
| 1256 |
+
"name": (item["name"][:14] + "..") if len(item["name"]) > 14 else item["name"],
|
| 1257 |
+
"pct_str": ("β² " if pct >= 0 else "βΌ ") + str(round(abs(pct), 1)) + "%",
|
| 1258 |
+
"price": format(item["current_price"], ",") + "μ",
|
| 1259 |
+
})
|
| 1260 |
+
data[tab] = rows
|
| 1261 |
+
|
| 1262 |
+
tab_json = json.dumps({t: {"icon": v["icon"], "accent": v["accent"],
|
| 1263 |
+
"bg": v["bg"], "border": v["border"]}
|
| 1264 |
+
for t, v in TAB_CFG.items()}, ensure_ascii=False)
|
| 1265 |
+
data_json = json.dumps(data, ensure_ascii=False)
|
| 1266 |
+
timer_col = "#E53E3E" if time_left <= 15 else ("#EAB308" if time_left <= 30 else "#8B98B4")
|
| 1267 |
+
|
| 1268 |
+
# iframe CSS: μ 체νλ©΄ ν¬λͺ
μ€λ²λ μ΄
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1269 |
st.markdown("""
|
| 1270 |
<style>
|
|
|
|
|
|
|
| 1271 |
iframe[title="components.v1.html"] {
|
| 1272 |
position: fixed !important;
|
| 1273 |
+
top: 0 !important; left: 0 !important;
|
| 1274 |
+
width: 100vw !important; height: 100vh !important;
|
| 1275 |
+
border: none !important; z-index: 2147483640 !important;
|
| 1276 |
+
background: transparent !important; pointer-events: none !important;
|
| 1277 |
+
}
|
| 1278 |
+
div:has(> iframe[title="components.v1.html"]) {
|
| 1279 |
+
height: 0 !important; overflow: visible !important;
|
| 1280 |
+
}
|
| 1281 |
+
</style>""", unsafe_allow_html=True)
|
| 1282 |
+
|
| 1283 |
+
B = badge_col
|
| 1284 |
+
T = str(time_left)
|
| 1285 |
+
N = str(total_cnt)
|
| 1286 |
+
TC = timer_col
|
| 1287 |
+
DMIN = "flex" if minimized else "none"
|
| 1288 |
+
DPAN = "none" if minimized else "block"
|
| 1289 |
+
IMIN = "true" if minimized else "false"
|
| 1290 |
+
ITAB = json.dumps(active_tab, ensure_ascii=False)
|
| 1291 |
+
|
| 1292 |
+
html = """<!DOCTYPE html>
|
| 1293 |
+
<html><head><meta charset='utf-8'>
|
| 1294 |
+
<link href='https://fonts.googleapis.com/css2?family=Noto+Sans+KR:wght@400;700;900&family=DM+Mono:wght@500;700&display=swap' rel='stylesheet'>
|
| 1295 |
+
<style>
|
| 1296 |
+
*{margin:0;padding:0;box-sizing:border-box;font-family:'Noto+Sans+KR',sans-serif}
|
| 1297 |
+
html,body{background:transparent;overflow:hidden;width:100vw;height:100vh}
|
| 1298 |
+
@keyframes slideUp{from{transform:translateY(20px);opacity:0}to{transform:none;opacity:1}}
|
| 1299 |
+
@keyframes badgePop{from{transform:scale(0.6);opacity:0}to{transform:scale(1);opacity:1}}
|
| 1300 |
+
@keyframes pulse{0%,100%{opacity:1}50%{opacity:.3}}
|
| 1301 |
+
@keyframes itemIn{from{transform:translateX(8px);opacity:0}to{transform:none;opacity:1}}
|
| 1302 |
+
#panel{position:fixed;bottom:24px;right:20px;width:min(96vw,360px);z-index:9999;animation:slideUp .4s cubic-bezier(.34,1.56,.64,1);pointer-events:auto}
|
| 1303 |
+
#badge{position:fixed;bottom:24px;right:20px;display:flex;align-items:center;gap:9px;
|
| 1304 |
+
background:linear-gradient(135deg,#1a2035,#131820);border:1px solid %(B)s;
|
| 1305 |
+
border-radius:40px;padding:10px 20px;cursor:pointer;z-index:9999;
|
| 1306 |
+
box-shadow:0 8px 32px rgba(0,0,0,.6);animation:badgePop .35s cubic-bezier(.34,1.56,.64,1);
|
| 1307 |
+
pointer-events:auto;user-select:none}
|
| 1308 |
+
#badge:hover{border-color:#fff}
|
| 1309 |
+
.tab-btn{transition:all .15s}
|
| 1310 |
+
.tab-btn:hover{opacity:.9!important}
|
| 1311 |
+
.alert-item{transition:all .15s;border:1px solid transparent;cursor:pointer}
|
| 1312 |
+
.alert-item:hover{background:rgba(255,255,255,.06)!important;transform:translateX(-2px)}
|
| 1313 |
+
.min-btn:hover{color:rgba(255,255,255,.7)!important;background:rgba(255,255,255,.08)!important}
|
| 1314 |
+
#body::-webkit-scrollbar{width:3px}
|
| 1315 |
+
#body::-webkit-scrollbar-thumb{background:rgba(255,255,255,.15);border-radius:3px}
|
| 1316 |
+
</style></head><body>
|
| 1317 |
+
|
| 1318 |
+
<div id='badge' style='display:%(DMIN)s'>
|
| 1319 |
+
<span style='font-size:20px;position:relative;line-height:1'>🔔
|
| 1320 |
+
<span style='position:absolute;top:-6px;right:-9px;background:%(B)s;color:#fff;
|
| 1321 |
+
border-radius:10px;font-size:9px;font-weight:700;min-width:17px;height:17px;
|
| 1322 |
+
display:flex;align-items:center;justify-content:center;padding:0 3px;
|
| 1323 |
+
font-family:DM Mono,monospace;box-shadow:0 0 8px %(B)s80'>%(N)s</span>
|
| 1324 |
+
</span>
|
| 1325 |
+
<span style='font-size:12px;font-weight:700;color:#e8eaf0'>μλ %(N)sκ°</span>
|
| 1326 |
+
<span style='width:6px;height:6px;border-radius:50%;background:%(B)s;animation:pulse 1.5s infinite;display:inline-block'></span>
|
| 1327 |
+
</div>
|
| 1328 |
+
|
| 1329 |
+
<div id='panel' style='display:%(DPAN)s'>
|
| 1330 |
+
<div style='background:linear-gradient(135deg,#1e2538,#161c2c);border:1px solid rgba(255,255,255,.09);border-bottom:none;border-radius:16px 16px 0 0;padding:13px 14px 0'>
|
| 1331 |
+
<div style='display:flex;align-items:center;justify-content:space-between;margin-bottom:12px'>
|
| 1332 |
+
<div style='display:flex;align-items:center;gap:7px'>
|
| 1333 |
+
<div style='width:7px;height:7px;border-radius:50%;background:#FF6B35;animation:pulse 1.5s infinite;box-shadow:0 0 8px rgba(255,107,53,.7)'></div>
|
| 1334 |
+
<span style='color:#eef2f7;font-size:12px;font-weight:700;letter-spacing:.08em'>LIVE ALERTS</span>
|
| 1335 |
+
<span style='background:rgba(229,62,62,.15);border:1px solid rgba(229,62,62,.3);border-radius:5px;padding:1px 7px;font-size:10px;color:#E53E3E;font-weight:700'>%(N)s</span>
|
| 1336 |
+
</div>
|
| 1337 |
+
<div style='display:flex;align-items:center;gap:6px'>
|
| 1338 |
+
<div style='background:rgba(255,255,255,.06);border-radius:8px;padding:3px 9px;display:flex;align-items:center;gap:4px'>
|
| 1339 |
+
<span style='font-size:11px'>⏱</span>
|
| 1340 |
+
<span id='timer' style='font-size:11px;font-weight:700;font-family:DM Mono,monospace;color:%(TC)s'>%(T)ss</span>
|
| 1341 |
+
</div>
|
| 1342 |
+
<button class='min-btn' onclick='minimize()' style='background:transparent;border:1px solid rgba(255,255,255,.1);border-radius:6px;color:rgba(255,255,255,.35);font-size:15px;padding:3px 8px;cursor:pointer;line-height:1'>−</button>
|
| 1343 |
+
</div>
|
| 1344 |
+
</div>
|
| 1345 |
+
<div id='tabs' style='display:flex;gap:3px'></div>
|
| 1346 |
+
</div>
|
| 1347 |
+
<div id='body' style='background:linear-gradient(180deg,#161c2a,#111620);border:1px solid rgba(255,255,255,.09);border-radius:0 0 16px 16px;max-height:260px;overflow-y:auto;padding:6px'></div>
|
| 1348 |
+
<button class='min-btn' onclick='minimize()' style='width:100%%;margin-top:4px;padding:6px;background:rgba(255,255,255,.04);border:1px solid rgba(255,255,255,.08);border-radius:9px;color:rgba(255,255,255,.35);font-size:11px;cursor:pointer;font-family:Noto Sans KR,sans-serif'>− μ΅μν</button>
|
| 1349 |
+
</div>
|
| 1350 |
+
|
| 1351 |
+
<script>
|
| 1352 |
+
var M=%(IMIN)s, T=%(T)s, TAB=%(ITAB)s;
|
| 1353 |
+
var TABS=%(TAB_JSON)s;
|
| 1354 |
+
var DATA=%(DATA_JSON)s;
|
| 1355 |
+
var te=document.getElementById('timer');
|
| 1356 |
+
|
| 1357 |
+
function renderTabs(){
|
| 1358 |
+
var el=document.getElementById('tabs'); el.innerHTML='';
|
| 1359 |
+
Object.keys(TABS).forEach(function(tab){
|
| 1360 |
+
var tc=TABS[tab], cnt=DATA[tab].length, isAct=tab===TAB;
|
| 1361 |
+
var d=document.createElement('div');
|
| 1362 |
+
d.className='tab-btn';
|
| 1363 |
+
d.style.cssText='flex:1;background:'+(isAct?tc.bg:'transparent')+
|
| 1364 |
+
';border:1px solid '+(isAct?tc.border:'rgba(255,255,255,0.06)')+
|
| 1365 |
+
';border-bottom:'+(isAct?'2px solid '+tc.accent:'1px solid transparent')+
|
| 1366 |
+
';border-radius:8px 8px 0 0;padding:7px 3px;cursor:pointer;'+
|
| 1367 |
+
'display:flex;flex-direction:column;align-items:center;gap:2px;'+
|
| 1368 |
+
'opacity:'+(isAct?'1':'0.55')+';';
|
| 1369 |
+
var bgb=cnt>0?tc.accent:'rgba(255,255,255,0.15)';
|
| 1370 |
+
var lc=isAct?tc.accent:'rgba(255,255,255,0.4)';
|
| 1371 |
+
d.innerHTML='<span style="font-size:13px">'+tc.icon+'</span>'+
|
| 1372 |
+
'<span style="font-size:9px;font-weight:700;color:'+lc+'">'+tab+'</span>'+
|
| 1373 |
+
'<span style="background:'+bgb+';color:#fff;border-radius:8px;'+
|
| 1374 |
+
'min-width:16px;height:16px;display:flex;align-items:center;'+
|
| 1375 |
+
'justify-content:center;font-size:9px;font-weight:700;padding:0 4px">'+cnt+'</span>';
|
| 1376 |
+
d.onclick=(function(t){return function(){switchTab(t);};})(tab);
|
| 1377 |
+
el.appendChild(d);
|
| 1378 |
+
});
|
| 1379 |
+
}
|
| 1380 |
+
|
| 1381 |
+
function renderBody(){
|
| 1382 |
+
var el=document.getElementById('body');
|
| 1383 |
+
var tc=TABS[TAB], items=DATA[TAB];
|
| 1384 |
+
el.style.borderTop='2px solid '+tc.accent;
|
| 1385 |
+
if(!items.length){
|
| 1386 |
+
el.innerHTML='<p style="text-align:center;padding:24px;color:rgba(255,255,255,0.2);font-size:13px;margin:0">μλ μμ</p>';
|
| 1387 |
+
return;
|
| 1388 |
+
}
|
| 1389 |
+
el.innerHTML='';
|
| 1390 |
+
items.forEach(function(item,i){
|
| 1391 |
+
var d=document.createElement('div');
|
| 1392 |
+
d.className='alert-item';
|
| 1393 |
+
d.style.cssText='display:flex;align-items:center;gap:10px;padding:9px 11px;border-radius:10px;margin-bottom:'+(i<items.length-1?'3px':'0')+';';
|
| 1394 |
+
d.style.animation='itemIn .3s ease '+(i*0.07)+'s both';
|
| 1395 |
+
d.innerHTML=
|
| 1396 |
+
'<div style="width:40px;height:40px;border-radius:9px;flex-shrink:0;'+
|
| 1397 |
+
'background:'+tc.bg+';border:1px solid '+tc.border+';'+
|
| 1398 |
+
'display:flex;align-items:center;justify-content:center;'+
|
| 1399 |
+
'font-size:9px;font-weight:800;color:'+tc.accent+';'+
|
| 1400 |
+
'font-family:DM Mono,monospace">'+item.ticker.slice(0,4)+'</div>'+
|
| 1401 |
+
'<div style="flex:1;min-width:0">'+
|
| 1402 |
+
'<div style="font-size:12px;font-weight:700;color:#eef2f7;margin-bottom:2px">'+
|
| 1403 |
+
item.ticker+' <span style="font-size:10px;color:rgba(255,255,255,0.3);font-weight:400">'+item.name+'</span></div>'+
|
| 1404 |
+
'<div style="font-size:11px;color:rgba(255,255,255,0.3)">'+item.price+'</div>'+
|
| 1405 |
+
'</div>'+
|
| 1406 |
+
'<div style="text-align:right;flex-shrink:0">'+
|
| 1407 |
+
'<div style="font-size:12px;font-weight:700;color:'+tc.accent+'">'+item.pct_str+'</div>'+
|
| 1408 |
+
'<div style="font-size:10px;color:rgba(255,255,255,0.2);margin-top:1px">→ λΆμ</div>'+
|
| 1409 |
+
'</div>';
|
| 1410 |
+
d.onclick=(function(tk){return function(){send('goto:'+tk);};})(item.ticker);
|
| 1411 |
+
el.appendChild(d);
|
| 1412 |
+
});
|
| 1413 |
+
}
|
| 1414 |
+
|
| 1415 |
+
renderTabs(); renderBody();
|
| 1416 |
+
|
| 1417 |
+
var iv=setInterval(function(){
|
| 1418 |
+
if(M)return; T--;
|
| 1419 |
+
if(T<=0){clearInterval(iv);minimize();send('expired');return;}
|
| 1420 |
+
if(te){te.textContent=T+'s';te.style.color=T<=15?'#E53E3E':T<=30?'#EAB308':'#8B98B4';}
|
| 1421 |
+
},1000);
|
| 1422 |
+
|
| 1423 |
+
function send(a){window.parent.postMessage({type:'alert_action',action:a},'*');}
|
| 1424 |
+
function minimize(){M=true;document.getElementById('panel').style.display='none';document.getElementById('badge').style.display='flex';send('minimize');}
|
| 1425 |
+
function openPanel(){
|
| 1426 |
+
M=false; T=60; clearInterval(iv);
|
| 1427 |
+
iv=setInterval(function(){if(M)return;T--;if(T<=0){clearInterval(iv);minimize();send('expired');return;}if(te){te.textContent=T+'s';te.style.color=T<=15?'#E53E3E':T<=30?'#EAB308':'#8B98B4';}},1000);
|
| 1428 |
+
if(te){te.textContent='60s';te.style.color='#8B98B4';}
|
| 1429 |
+
document.getElementById('badge').style.display='none';
|
| 1430 |
+
document.getElementById('panel').style.display='block';
|
| 1431 |
+
send('open');
|
| 1432 |
+
}
|
| 1433 |
+
function switchTab(t){TAB=t;renderTabs();renderBody();send('tab:'+t);}
|
| 1434 |
+
document.getElementById('badge').onclick=openPanel;
|
| 1435 |
+
</script>
|
| 1436 |
+
</body></html>""" % {
|
| 1437 |
+
"B": B, "T": T, "N": N, "TC": TC,
|
| 1438 |
+
"DMIN": DMIN, "DPAN": DPAN, "IMIN": IMIN, "ITAB": ITAB,
|
| 1439 |
+
"TAB_JSON": tab_json, "DATA_JSON": data_json,
|
| 1440 |
+
}
|
| 1441 |
+
|
| 1442 |
+
# postMessage β URL query λ³ν (Streamlit 리λ λ νΈλ¦¬κ±°)
|
| 1443 |
st.markdown("""
|
| 1444 |
<script>
|
| 1445 |
+
window.addEventListener('message', function(e){
|
| 1446 |
+
if(!e.data||e.data.type!=='alert_action') return;
|
| 1447 |
+
var base=window.location.href.split('?')[0];
|
| 1448 |
+
window.location.href=base+'?alert_action='+encodeURIComponent(e.data.action);
|
| 1449 |
});
|
| 1450 |
+
</script>""", unsafe_allow_html=True)
|
|
|
|
| 1451 |
|
| 1452 |
components.html(html, height=0, scrolling=False)
|
| 1453 |
|