Spaces:
Runtime error

ditgun commited on
Commit
ecddd31
Β·
verified Β·
1 Parent(s): 004504c

Update src/app.py

Browse files
Files changed (1) hide show
  1. src/app.py +303 -367
src/app.py CHANGED
@@ -1128,21 +1128,20 @@ def _navigate_to_ticker(ticker):
1128
 
1129
 
1130
  def render_grouped_alert_panel(prices, rate):
 
 
 
 
1131
  groups = _build_alert_groups(prices, rate)
1132
  total_cnt = sum(len(v) for v in groups.values())
1133
  if total_cnt == 0:
1134
  return
1135
 
1136
- elapsed = time.time() - st.session_state.alert_panel_start_time
1137
- time_left = max(0, 60 - int(elapsed))
1138
- if time_left == 0 and not st.session_state.alert_panel_minimized:
1139
- st.session_state.alert_panel_minimized = True
1140
-
1141
  TAB_CFG = {
1142
- "κΈ‰λ³€": {"icon": "⚑", "accent": "#FF6B35", "bg": "rgba(255,107,53,0.10)", "border": "rgba(255,107,53,0.30)"},
1143
- "맀수": {"icon": "πŸ“ˆ", "accent": "#00D4AA", "bg": "rgba(0,212,170,0.10)", "border": "rgba(0,212,170,0.30)"},
1144
- "읡절": {"icon": "βœ…", "accent": "#4299E1", "bg": "rgba(66,153,225,0.10)", "border": "rgba(66,153,225,0.30)"},
1145
- "μŠ€ν†±λ‘œμŠ€": {"icon": "πŸ›‘", "accent": "#E53E3E", "bg": "rgba(229,62,62,0.10)", "border": "rgba(229,62,62,0.30)"},
1146
  }
1147
 
1148
  sl_cnt = len(groups["μŠ€ν†±λ‘œμŠ€"])
@@ -1157,386 +1156,346 @@ def render_grouped_alert_panel(prices, rate):
1157
  else:
1158
  st.session_state.alert_active_tab = "κΈ‰λ³€"
1159
  active_tab = st.session_state.alert_active_tab
 
1160
 
1161
- data = {}
1162
- for tab, tc in TAB_CFG.items():
1163
- rows = []
1164
- for item in groups[tab]:
1165
- pct = item["change_pct"]
1166
- rows.append({
1167
- "ticker": item["ticker"],
1168
- "name": (item["name"][:14] + "..") if len(item["name"]) > 14 else item["name"],
1169
- "pct_str": ("β–² " if pct >= 0 else "β–Ό ") + str(round(abs(pct), 1)) + "%",
1170
- "price": format(item["current_price"], ",") + "원",
1171
- })
1172
- data[tab] = rows
1173
-
1174
- tab_json = json.dumps(
1175
- {t: {"icon": v["icon"], "accent": v["accent"], "bg": v["bg"], "border": v["border"]}
1176
- for t, v in TAB_CFG.items()},
1177
- ensure_ascii=False
1178
- )
1179
- data_json = json.dumps(data, ensure_ascii=False)
1180
- timer_col = "#E53E3E" if time_left <= 15 else ("#EAB308" if time_left <= 30 else "#8B98B4")
1181
-
1182
- B = badge_col
1183
- T = str(time_left)
1184
- N = str(total_cnt)
1185
- TC = timer_col
1186
- IMIN = "true" if minimized else "false"
1187
- ITAB = json.dumps(active_tab, ensure_ascii=False)
1188
- # CSS display 값은 직접 λ¬Έμžμ—΄λ‘œ 처리 (% ν¬λ§€νŒ… 좩돌 λ°©μ§€)
1189
- DMIN = "flex" if minimized else "none"
1190
- DPAN = "none" if minimized else "flex"
1191
-
1192
- html_template = """<!DOCTYPE html>
1193
- <html>
1194
- <head>
1195
- <meta charset="utf-8">
1196
- <link href="https://fonts.googleapis.com/css2?family=JetBrains+Mono:wght@600;700;800&family=Noto+Sans+KR:wght@400;500;700;900&display=swap" rel="stylesheet">
1197
  <style>
1198
- * { margin:0; padding:0; box-sizing:border-box; }
1199
- html, body {
1200
- background: transparent;
1201
- overflow: hidden;
1202
- width: 100vw;
1203
- height: 100vh;
1204
- font-family: 'Noto Sans KR', sans-serif;
1205
- }
1206
- #alert-root {
1207
- position: fixed;
1208
- bottom: 24px;
1209
- right: 20px;
1210
- z-index: 9999;
1211
- pointer-events: auto;
1212
  }
1213
- #badge {
 
 
 
1214
  align-items: center;
1215
- gap: 10px;
1216
- background: linear-gradient(135deg, #1a1f2e 0%%, #151921 100%%);
1217
- border: 1px solid __BADGE_COL__;
1218
  border-radius: 40px;
1219
- padding: 10px 20px;
1220
  cursor: pointer;
1221
- box-shadow: 0 8px 32px rgba(0,0,0,0.55), 0 0 0 1px rgba(255,255,255,0.04);
1222
- animation: badgePop 0.4s cubic-bezier(0.34,1.56,0.64,1);
1223
- user-select: none;
1224
- transition: border-color 0.2s;
1225
- }
1226
- #badge:hover { border-color: rgba(255,255,255,0.3); }
1227
- .badge-dot {
1228
- width: 6px; height: 6px; border-radius: 50%%;
1229
- background: __BADGE_COL__;
1230
- animation: pulse 1.5s infinite;
1231
- display: inline-block;
1232
  }
1233
- #panel {
1234
- flex-direction: column;
1235
- width: min(96vw, 380px);
1236
- animation: slideUp 0.4s cubic-bezier(0.34,1.56,0.64,1);
1237
- }
1238
- .p-header {
1239
- background: linear-gradient(135deg, #1e2538 0%%, #161c2c 100%%);
1240
  border: 1px solid rgba(255,255,255,0.09);
1241
  border-bottom: none;
1242
- border-radius: 16px 16px 0 0;
1243
- padding: 14px 16px 0;
1244
  }
1245
- .p-header-row {
1246
- display: flex; align-items: center;
 
1247
  justify-content: space-between;
1248
- margin-bottom: 14px;
1249
- }
1250
- .live-dot {
1251
- width: 8px; height: 8px; border-radius: 50%%;
1252
- background: #FF6B35;
1253
- box-shadow: 0 0 8px rgba(255,107,53,0.8);
1254
- animation: pulse 1.5s infinite;
1255
- display: inline-block;
1256
- }
1257
- .live-label {
1258
- font-size: 12px; font-weight: 700; color: #e8eaf0;
1259
- letter-spacing: 0.08em;
1260
- font-family: 'JetBrains Mono', monospace;
1261
- }
1262
- .total-badge {
1263
- background: rgba(229,62,62,0.15);
1264
- border: 1px solid rgba(229,62,62,0.3);
1265
- border-radius: 5px; padding: 1px 7px;
1266
- font-size: 10px; color: #E53E3E; font-weight: 700;
1267
- font-family: 'JetBrains Mono', monospace;
1268
  }
1269
- .timer-wrap {
1270
- display: flex; align-items: center; gap: 5px;
1271
- background: rgba(255,255,255,0.06);
1272
- border-radius: 8px; padding: 4px 10px;
1273
- }
1274
- .min-btn {
1275
- background: transparent;
1276
- border: 1px solid rgba(255,255,255,0.1);
1277
- border-radius: 6px;
1278
- color: rgba(255,255,255,0.35);
1279
- font-size: 16px; padding: 3px 9px;
1280
- cursor: pointer; line-height: 1;
1281
- transition: all 0.15s;
1282
- font-family: 'JetBrains Mono', monospace;
1283
  }
1284
- .min-btn:hover { background: rgba(255,255,255,0.1); color: rgba(255,255,255,0.7); }
1285
- .tabs-row { display: flex; gap: 4px; }
1286
- .tab-btn {
1287
  flex: 1;
 
 
 
 
 
 
1288
  border: 1px solid rgba(255,255,255,0.06);
1289
  border-bottom: none;
1290
- border-radius: 8px 8px 0 0;
1291
- padding: 8px 3px;
1292
- cursor: pointer;
1293
- display: flex; flex-direction: column; align-items: center; gap: 3px;
1294
- transition: all 0.18s;
1295
- background: transparent;
1296
- }
1297
- .tab-btn:hover { opacity: 0.9 !important; }
1298
- .tab-icon { font-size: 14px; }
1299
- .tab-label { font-size: 9px; font-weight: 700; letter-spacing: 0.04em; font-family: 'Noto Sans KR', sans-serif; }
1300
- .tab-count {
1301
- border-radius: 8px; min-width: 16px; height: 16px;
1302
- display: flex; align-items: center; justify-content: center;
1303
- font-size: 9px; font-weight: 700; padding: 0 4px; color: #fff;
1304
- font-family: 'JetBrains Mono', monospace;
1305
  }
1306
- .p-body {
1307
- background: linear-gradient(180deg, #161c2a 0%%, #111620 100%%);
 
 
1308
  border: 1px solid rgba(255,255,255,0.09);
1309
- border-radius: 0 0 16px 16px;
1310
- max-height: 280px;
 
1311
  overflow-y: auto;
1312
- padding: 8px;
1313
  }
1314
- .p-body::-webkit-scrollbar { width: 3px; }
1315
- .p-body::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.15); border-radius: 3px; }
1316
- .alert-item {
1317
- display: flex; align-items: center; gap: 12px;
1318
- padding: 10px 12px;
 
 
 
 
1319
  border-radius: 10px;
1320
- cursor: pointer;
1321
  border: 1px solid transparent;
1322
- margin-bottom: 4px;
1323
- transition: all 0.15s ease;
1324
- animation: itemIn 0.3s ease both;
1325
  }
1326
- .alert-item:last-child { margin-bottom: 0; }
1327
- .alert-item:hover { background: rgba(255,255,255,0.06) !important; transform: translateX(-2px); }
1328
- .ticker-box {
1329
- width: 40px; height: 40px; border-radius: 10px;
1330
  display: flex; align-items: center; justify-content: center;
1331
  flex-shrink: 0;
1332
- font-size: 9px; font-weight: 800; letter-spacing: -0.02em;
1333
  font-family: 'JetBrains Mono', monospace;
 
1334
  }
1335
- .item-name { font-size: 12px; font-weight: 700; color: #e8eaf0; margin-bottom: 2px; }
1336
- .item-sub { font-size: 10px; color: rgba(255,255,255,0.35); font-family: 'Noto Sans KR', sans-serif; }
1337
- .item-price { font-size: 11px; color: rgba(255,255,255,0.4); margin-top: 1px; font-family: 'Noto Sans KR', sans-serif; }
1338
- .item-pct { font-size: 12px; font-weight: 700; font-family: 'JetBrains Mono', monospace; }
1339
- .item-arrow { font-size: 10px; color: rgba(255,255,255,0.25); margin-top: 2px; }
1340
- .empty-msg { text-align: center; padding: 24px; color: rgba(255,255,255,0.2); font-size: 13px; }
1341
- @keyframes slideUp {
1342
- from { transform: translateY(30px); opacity: 0; }
1343
- to { transform: translateY(0); opacity: 1; }
1344
  }
1345
- @keyframes badgePop {
1346
- from { transform: scale(0.5); opacity: 0; }
1347
- to { transform: scale(1); opacity: 1; }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1348
  }
1349
- @keyframes pulse {
1350
- 0%%, 100%% { opacity: 1; }
1351
- 50%% { opacity: 0.3; }
1352
  }
1353
- @keyframes itemIn {
1354
- from { transform: translateX(10px); opacity: 0; }
1355
- to { transform: translateX(0); opacity: 1; }
1356
  }
1357
  </style>
1358
- </head>
1359
- <body>
1360
- <div id="alert-root">
1361
-
1362
- <!-- μ΅œμ†Œν™” λ°°μ§€ -->
1363
- <div id="badge" style="display:__DMIN__;">
1364
- <span style="font-size:20px;position:relative;line-height:1;">&#x1F514;
1365
- <span style="position:absolute;top:-7px;right:-10px;
1366
- background:__BADGE_COL__;color:#fff;border-radius:10px;
1367
- font-size:9px;font-weight:700;min-width:18px;height:18px;
1368
- display:flex;align-items:center;justify-content:center;padding:0 4px;
1369
- font-family:'JetBrains Mono',monospace;
1370
- box-shadow:0 0 8px __BADGE_COL__80;">__N__</span>
1371
  </span>
1372
- <span style="font-size:13px;font-weight:700;color:#e8eaf0;font-family:'JetBrains Mono',monospace;">μ•ŒλžŒ __N__개</span>
1373
- <span class="badge-dot"></span>
1374
- </div>
1375
-
1376
- <!-- ν’€ νŒ¨λ„ -->
1377
- <div id="panel" style="display:__DPAN__;">
1378
- <div class="p-header">
1379
- <div class="p-header-row">
1380
- <div style="display:flex;align-items:center;gap:8px;">
1381
- <span class="live-dot"></span>
1382
- <span class="live-label">LIVE ALERTS</span>
1383
- <span class="total-badge">__N__</span>
1384
- </div>
1385
- <div style="display:flex;align-items:center;gap:6px;">
1386
- <div class="timer-wrap">
1387
- <span style="font-size:12px;">&#x23F1;</span>
1388
- <span id="timer-txt"
1389
- style="font-size:11px;font-weight:700;font-family:'JetBrains Mono',monospace;color:__TC__;">__T__s</span>
1390
- </div>
1391
- <button class="min-btn" onclick="minimize()">&#x2212;</button>
1392
- </div>
1393
- </div>
1394
- <div class="tabs-row" id="tabs-row"></div>
1395
- </div>
1396
- <div class="p-body" id="panel-body"></div>
1397
  </div>
1398
-
1399
  </div>
 
1400
 
1401
- <script>
1402
- var MINIMIZED = __IMIN__;
1403
- var TIME_LEFT = __T__;
1404
- var ACTIVE_TAB = __ITAB__;
1405
- var TABS = __TAB_JSON__;
1406
- var DATA = __DATA_JSON__;
1407
- var timerEl = document.getElementById('timer-txt');
1408
-
1409
- function renderTabs() {
1410
- var el = document.getElementById('tabs-row');
1411
- el.innerHTML = '';
1412
- Object.keys(TABS).forEach(function(tab) {
1413
- var tc = TABS[tab];
1414
- var cnt = DATA[tab].length;
1415
- var isA = (tab === ACTIVE_TAB);
1416
- var btn = document.createElement('div');
1417
- btn.className = 'tab-btn';
1418
- btn.style.cssText =
1419
- 'background:' + (isA ? tc.bg : 'transparent') + ';' +
1420
- 'border-color:' + (isA ? tc.border : 'rgba(255,255,255,0.06)') + ';' +
1421
- 'border-bottom:' + (isA ? '2px solid ' + tc.accent : '1px solid transparent') + ';' +
1422
- 'opacity:' + (isA ? '1' : '0.55') + ';';
1423
- btn.innerHTML =
1424
- '<span class="tab-icon">' + tc.icon + '</span>' +
1425
- '<span class="tab-label" style="color:' + (isA ? tc.accent : 'rgba(255,255,255,0.4)') + '">' + tab + '</span>' +
1426
- '<span class="tab-count" style="background:' + (cnt > 0 ? tc.accent : 'rgba(255,255,255,0.15)') + '">' + cnt + '</span>';
1427
- btn.onclick = (function(t) { return function() { switchTab(t); }; })(tab);
1428
- el.appendChild(btn);
1429
- });
1430
  }
 
 
 
 
 
 
 
 
 
1431
 
1432
- function renderBody() {
1433
- var el = document.getElementById('panel-body');
1434
- var tc = TABS[ACTIVE_TAB];
1435
- var items = DATA[ACTIVE_TAB];
1436
- el.style.borderTop = '2px solid ' + tc.accent;
1437
- el.innerHTML = '';
1438
- if (!items.length) {
1439
- el.innerHTML = '<div class="empty-msg">μ•ŒλžŒ μ—†μŒ</div>';
1440
- return;
1441
- }
1442
- items.forEach(function(item, i) {
1443
- var row = document.createElement('div');
1444
- row.className = 'alert-item';
1445
- row.style.animationDelay = (i * 0.06) + 's';
1446
- row.innerHTML =
1447
- '<div class="ticker-box" style="background:' + tc.bg + ';border:1px solid ' + tc.border + ';color:' + tc.accent + ';">' +
1448
- item.ticker.slice(0, 4) +
1449
- '</div>' +
1450
- '<div style="flex:1;min-width:0;">' +
1451
- '<div class="item-name">' + item.ticker + ' <span class="item-sub">' + item.name + '</span></div>' +
1452
- '<div class="item-price">' + item.price + '</div>' +
1453
- '</div>' +
1454
- '<div style="text-align:right;flex-shrink:0;">' +
1455
- '<div class="item-pct" style="color:' + tc.accent + ';">' + item.pct_str + '</div>' +
1456
- '<div class="item-arrow">&#x2192; 뢄석</div>' +
1457
- '</div>';
1458
- row.onclick = (function(tk) { return function() { sendAction('goto:' + tk); }; })(item.ticker);
1459
- el.appendChild(row);
1460
- });
1461
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1462
 
1463
- renderTabs();
1464
- renderBody();
1465
-
1466
- var iv = setInterval(function() {
1467
- if (MINIMIZED) return;
1468
- TIME_LEFT--;
1469
- if (TIME_LEFT <= 0) {
1470
- clearInterval(iv);
1471
- minimize();
1472
- sendAction('expired');
1473
- return;
1474
- }
1475
- if (timerEl) {
1476
- timerEl.textContent = TIME_LEFT + 's';
1477
- timerEl.style.color = TIME_LEFT <= 15 ? '#E53E3E' : (TIME_LEFT <= 30 ? '#EAB308' : '#8B98B4');
1478
- }
1479
- }, 1000);
1480
 
1481
- function minimize() {
1482
- MINIMIZED = true;
1483
- document.getElementById('panel').style.display = 'none';
1484
- document.getElementById('badge').style.display = 'flex';
1485
- sendAction('minimize');
1486
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
1487
 
1488
- function openPanel() {
1489
- MINIMIZED = false;
1490
- TIME_LEFT = 60;
1491
- clearInterval(iv);
1492
- iv = setInterval(function() {
1493
- if (MINIMIZED) return;
1494
- TIME_LEFT--;
1495
- if (TIME_LEFT <= 0) { clearInterval(iv); minimize(); sendAction('expired'); return; }
1496
- if (timerEl) {
1497
- timerEl.textContent = TIME_LEFT + 's';
1498
- timerEl.style.color = TIME_LEFT <= 15 ? '#E53E3E' : (TIME_LEFT <= 30 ? '#EAB308' : '#8B98B4');
1499
- }
1500
- }, 1000);
1501
- if (timerEl) { timerEl.textContent = '60s'; timerEl.style.color = '#8B98B4'; }
1502
- document.getElementById('badge').style.display = 'none';
1503
- document.getElementById('panel').style.display = 'flex';
1504
- sendAction('open');
1505
- }
1506
 
1507
- function switchTab(t) {
1508
- ACTIVE_TAB = t;
1509
- renderTabs();
1510
- renderBody();
1511
- sendAction('tab:' + t);
1512
- }
1513
 
1514
- document.getElementById('badge').onclick = openPanel;
1515
 
1516
- function sendAction(action) {
1517
- try {
1518
- var base = window.parent.location.href.split('?')[0];
1519
- window.parent.location.href = base + '?alert_action=' + encodeURIComponent(action);
1520
- } catch(e) {}
 
 
 
 
 
 
 
 
 
1521
  }
1522
- </script>
1523
- </body>
1524
- </html>"""
1525
-
1526
- # ν”Œλ ˆμ΄μŠ€ν™€λ” μΉ˜ν™˜ (% ν¬λ§€νŒ… μ™„μ „ 우회)
1527
- html = html_template
1528
- html = html.replace("__BADGE_COL__", B)
1529
- html = html.replace("__N__", N)
1530
- html = html.replace("__T__", T)
1531
- html = html.replace("__TC__", TC)
1532
- html = html.replace("__DMIN__", DMIN)
1533
- html = html.replace("__DPAN__", DPAN)
1534
- html = html.replace("__IMIN__", IMIN)
1535
- html = html.replace("__ITAB__", ITAB)
1536
- html = html.replace("__TAB_JSON__", tab_json)
1537
- html = html.replace("__DATA_JSON__", data_json)
1538
-
1539
- components.html(html, height=0, scrolling=False)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1540
 
1541
 
1542
  # ============================================================
@@ -2120,26 +2079,3 @@ with nc[0]: st.button("*≑*\n메뉴", key="nav_menu", on_click=toggle_menu,
2120
  with nc[1]: st.button("*βŒ‚*\nν™ˆ", key="nav_home", on_click=go_home, use_container_width=True)
2121
  with nc[2]: st.button("*β˜…*\n관심", key="nav_fav", on_click=lambda: select_menu("β˜… 관심 μ’…λͺ©"), use_container_width=True)
2122
  with nc[3]: st.button("*β€Ή*\nλ’€λ‘œ", key="nav_back", on_click=go_back, use_container_width=True)
2123
-
2124
- # ── 디버그: νŒ¨λ„ κ°•μ œ λ Œλ” ──────────────────────────────────
2125
- components.html("""<!DOCTYPE html>
2126
- <html><head><meta charset="utf-8">
2127
- <style>
2128
- * { margin:0; padding:0; }
2129
- html, body { background:transparent; overflow:hidden; width:100vw; height:100vh; }
2130
- #box {
2131
- position: fixed;
2132
- bottom: 80px;
2133
- right: 20px;
2134
- background: red;
2135
- color: white;
2136
- padding: 20px;
2137
- border-radius: 10px;
2138
- font-size: 16px;
2139
- font-weight: bold;
2140
- z-index: 9999;
2141
- pointer-events: auto;
2142
- }
2143
- </style></head>
2144
- <body><div id="box">βœ… iframe μž‘λ™μ€‘</div></body></html>
2145
- """, height=0, scrolling=False)
 
1128
 
1129
 
1130
  def render_grouped_alert_panel(prices, rate):
1131
+ """
1132
+ st.markdown 기반 μ•ŒλžŒ νŒ¨λ„ β€” HuggingFace Spaces μ™„μ „ ν˜Έν™˜
1133
+ components.html λ―Έμ‚¬μš©. position:fixed CSS + Streamlit λ²„νŠΌμœΌλ‘œ μƒν˜Έμž‘μš©.
1134
+ """
1135
  groups = _build_alert_groups(prices, rate)
1136
  total_cnt = sum(len(v) for v in groups.values())
1137
  if total_cnt == 0:
1138
  return
1139
 
 
 
 
 
 
1140
  TAB_CFG = {
1141
+ "κΈ‰λ³€": {"icon": "⚑", "accent": "#FF6B35", "bg": "rgba(255,107,53,0.12)", "border": "rgba(255,107,53,0.35)"},
1142
+ "맀수": {"icon": "πŸ“ˆ", "accent": "#00D4AA", "bg": "rgba(0,212,170,0.12)", "border": "rgba(0,212,170,0.35)"},
1143
+ "읡절": {"icon": "βœ…", "accent": "#4299E1", "bg": "rgba(66,153,225,0.12)", "border": "rgba(66,153,225,0.35)"},
1144
+ "μŠ€ν†±λ‘œμŠ€": {"icon": "πŸ›‘", "accent": "#E53E3E", "bg": "rgba(229,62,62,0.12)", "border": "rgba(229,62,62,0.35)"},
1145
  }
1146
 
1147
  sl_cnt = len(groups["μŠ€ν†±λ‘œμŠ€"])
 
1156
  else:
1157
  st.session_state.alert_active_tab = "κΈ‰λ³€"
1158
  active_tab = st.session_state.alert_active_tab
1159
+ tc = TAB_CFG[active_tab]
1160
 
1161
+ # ── 곡톡 CSS (ν•œ 번만 μ£Όμž…) ──────────────────────────────
1162
+ st.markdown("""
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1163
  <style>
1164
+ @import url('https://fonts.googleapis.com/css2?family=JetBrains+Mono:wght@600;700;800&family=Noto+Sans+KR:wght@400;700;900&display=swap');
1165
+
1166
+ /* νŒ¨λ„ 전체 래퍼 β€” μš°ν•˜λ‹¨ κ³ μ • */
1167
+ .alert-float-wrap {
1168
+ position: fixed !important;
1169
+ bottom: 76px !important;
1170
+ right: 16px !important;
1171
+ width: 360px !important;
1172
+ z-index: 99999 !important;
1173
+ font-family: 'Noto Sans KR', sans-serif !important;
 
 
 
 
1174
  }
1175
+
1176
+ /* μ΅œμ†Œν™” λ°°μ§€ */
1177
+ .alert-badge {
1178
+ display: flex;
1179
  align-items: center;
1180
+ gap: 9px;
1181
+ background: linear-gradient(135deg, #1a1f2e, #151921);
 
1182
  border-radius: 40px;
1183
+ padding: 10px 18px;
1184
  cursor: pointer;
1185
+ box-shadow: 0 8px 28px rgba(0,0,0,0.6);
1186
+ width: fit-content;
1187
+ margin-left: auto;
 
 
 
 
 
 
 
 
1188
  }
1189
+
1190
+ /* νŒ¨λ„ 헀더 */
1191
+ .alert-panel-hdr {
1192
+ background: linear-gradient(135deg, #1e2538, #161c2c);
 
 
 
1193
  border: 1px solid rgba(255,255,255,0.09);
1194
  border-bottom: none;
1195
+ border-radius: 14px 14px 0 0;
1196
+ padding: 13px 14px 0;
1197
  }
1198
+ .alert-hdr-row {
1199
+ display: flex;
1200
+ align-items: center;
1201
  justify-content: space-between;
1202
+ margin-bottom: 12px;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1203
  }
1204
+
1205
+ /* νƒ­ ν–‰ */
1206
+ .alert-tabs {
1207
+ display: flex;
1208
+ gap: 3px;
 
 
 
 
 
 
 
 
 
1209
  }
1210
+ .alert-tab-item {
 
 
1211
  flex: 1;
1212
+ border-radius: 8px 8px 0 0;
1213
+ padding: 7px 3px;
1214
+ display: flex;
1215
+ flex-direction: column;
1216
+ align-items: center;
1217
+ gap: 2px;
1218
  border: 1px solid rgba(255,255,255,0.06);
1219
  border-bottom: none;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1220
  }
1221
+
1222
+ /* νŒ¨λ„ λ°”λ”” */
1223
+ .alert-panel-body {
1224
+ background: linear-gradient(180deg, #161c2a, #111620);
1225
  border: 1px solid rgba(255,255,255,0.09);
1226
+ border-radius: 0 0 14px 14px;
1227
+ padding: 7px;
1228
+ max-height: 270px;
1229
  overflow-y: auto;
 
1230
  }
1231
+ .alert-panel-body::-webkit-scrollbar { width: 3px; }
1232
+ .alert-panel-body::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.15); border-radius: 3px; }
1233
+
1234
+ /* μ•ŒλžŒ μ•„μ΄ν…œ */
1235
+ .alert-row {
1236
+ display: flex;
1237
+ align-items: center;
1238
+ gap: 11px;
1239
+ padding: 9px 11px;
1240
  border-radius: 10px;
 
1241
  border: 1px solid transparent;
1242
+ margin-bottom: 3px;
1243
+ transition: background 0.15s;
1244
+ cursor: pointer;
1245
  }
1246
+ .alert-row:hover { background: rgba(255,255,255,0.05) !important; }
1247
+ .alert-ticker-sq {
1248
+ width: 38px; height: 38px;
1249
+ border-radius: 9px;
1250
  display: flex; align-items: center; justify-content: center;
1251
  flex-shrink: 0;
1252
+ font-size: 9px; font-weight: 800;
1253
  font-family: 'JetBrains Mono', monospace;
1254
+ letter-spacing: -0.02em;
1255
  }
1256
+
1257
+ /* λ²„νŠΌ μ™„μ „ 숨기기 β€” μ•ŒλžŒ νŒ¨λ„ λ‚΄λΆ€ st.button */
1258
+ div[data-testid="stVerticalBlock"]:has(.alert-float-wrap) div.stButton > button {
1259
+ all: unset !important;
1260
+ cursor: pointer !important;
1261
+ display: block !important;
1262
+ width: 100% !important;
 
 
1263
  }
1264
+
1265
+ /* μ΅œμ†Œν™”/μ—΄κΈ°/νƒ­/μ’…λͺ© λ²„νŠΌ 곡톡 리셋 */
1266
+ .alert-btn-reset > div.stButton > button {
1267
+ background: transparent !important;
1268
+ border: none !important;
1269
+ box-shadow: none !important;
1270
+ padding: 0 !important;
1271
+ margin: 0 !important;
1272
+ color: inherit !important;
1273
+ font-size: inherit !important;
1274
+ font-weight: inherit !important;
1275
+ width: 100% !important;
1276
+ text-align: left !important;
1277
+ cursor: pointer !important;
1278
+ }
1279
+ .alert-btn-reset > div.stButton > button p {
1280
+ margin: 0 !important;
1281
+ color: inherit !important;
1282
+ font-size: inherit !important;
1283
+ white-space: pre-wrap !important;
1284
+ }
1285
+
1286
+ @keyframes alertSlideUp {
1287
+ from { transform: translateY(20px); opacity: 0; }
1288
+ to { transform: translateY(0); opacity: 1; }
1289
  }
1290
+ @keyframes alertPulse {
1291
+ 0%, 100% { opacity: 1; } 50% { opacity: 0.3; }
 
1292
  }
1293
+ @keyframes alertBadgePop {
1294
+ from { transform: scale(0.6); opacity: 0; }
1295
+ to { transform: scale(1); opacity: 1; }
1296
  }
1297
  </style>
1298
+ """, unsafe_allow_html=True)
1299
+
1300
+ # ── μ΅œμ†Œν™” λ°°μ§€ ──────────────────────────────────────────
1301
+ if minimized:
1302
+ st.markdown(f"""
1303
+ <div class="alert-float-wrap" style="animation: alertBadgePop 0.35s cubic-bezier(0.34,1.56,0.64,1);">
1304
+ <div class="alert-badge" style="border: 1px solid {badge_col};">
1305
+ <span style="font-size:19px; position:relative; line-height:1;">πŸ””
1306
+ <span style="position:absolute; top:-6px; right:-9px;
1307
+ background:{badge_col}; color:#fff; border-radius:10px;
1308
+ font-size:9px; font-weight:700; min-width:17px; height:17px;
1309
+ display:flex; align-items:center; justify-content:center; padding:0 3px;
1310
+ font-family:'JetBrains Mono',monospace;">{total_cnt}</span>
1311
  </span>
1312
+ <span style="font-size:12px; font-weight:700; color:#e8eaf0; font-family:'JetBrains Mono',monospace;">μ•ŒλžŒ {total_cnt}개</span>
1313
+ <span style="width:6px; height:6px; border-radius:50%; background:{badge_col};
1314
+ animation:alertPulse 1.5s infinite; display:inline-block;"></span>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1315
  </div>
 
1316
  </div>
1317
+ """, unsafe_allow_html=True)
1318
 
1319
+ # λ°°μ§€ 클릭 β†’ μ—΄κΈ° λ²„νŠΌ (μˆ¨κΉ€ 처리, λ°°μ§€ μœ„μ— 투λͺ… μ˜€λ²„λ ˆμ΄)
1320
+ st.markdown("""
1321
+ <style>
1322
+ .alert-open-btn > div.stButton > button {
1323
+ position: fixed !important;
1324
+ bottom: 76px !important;
1325
+ right: 16px !important;
1326
+ width: 180px !important;
1327
+ height: 44px !important;
1328
+ opacity: 0 !important;
1329
+ cursor: pointer !important;
1330
+ z-index: 999999 !important;
1331
+ background: transparent !important;
1332
+ border: none !important;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1333
  }
1334
+ </style>
1335
+ <div class="alert-open-btn">
1336
+ """, unsafe_allow_html=True)
1337
+ if st.button("μ•ŒλžŒμ—΄κΈ°", key="alert_open_btn"):
1338
+ st.session_state.alert_panel_minimized = False
1339
+ st.session_state.alert_panel_start_time = time.time()
1340
+ st.rerun()
1341
+ st.markdown("</div>", unsafe_allow_html=True)
1342
+ return
1343
 
1344
+ # ── ν’€ νŒ¨λ„ ──────────────────────────────────────────────
1345
+ # νƒ­ HTML 생성
1346
+ tabs_html = ""
1347
+ for tab_name, tcfg in TAB_CFG.items():
1348
+ cnt = len(groups[tab_name])
1349
+ is_a = (tab_name == active_tab)
1350
+ bg = tcfg["bg"] if is_a else "transparent"
1351
+ brd = tcfg["border"] if is_a else "rgba(255,255,255,0.06)"
1352
+ bb = f"2px solid {tcfg['accent']}" if is_a else "1px solid transparent"
1353
+ op = "1" if is_a else "0.5"
1354
+ lc = tcfg["accent"] if is_a else "rgba(255,255,255,0.4)"
1355
+ badge_bg = tcfg["accent"] if cnt > 0 else "rgba(255,255,255,0.15)"
1356
+ tabs_html += f"""
1357
+ <div class="alert-tab-item" style="background:{bg}; border-color:{brd}; border-bottom:{bb}; opacity:{op};">
1358
+ <span style="font-size:13px;">{tcfg['icon']}</span>
1359
+ <span style="font-size:9px; font-weight:700; color:{lc};">{tab_name}</span>
1360
+ <span style="background:{badge_bg}; color:#fff; border-radius:8px;
1361
+ min-width:15px; height:15px; display:flex; align-items:center; justify-content:center;
1362
+ font-size:9px; font-weight:700; padding:0 3px;">{cnt}</span>
1363
+ </div>"""
1364
+
1365
+ # μ•„μ΄ν…œ HTML 생성
1366
+ items_html = ""
1367
+ for item in groups[active_tab]:
1368
+ pct = item["change_pct"]
1369
+ pct_str = ("β–² " if pct >= 0 else "β–Ό ") + str(round(abs(pct), 1)) + "%"
1370
+ nm = (item["name"][:13] + "..") if len(item["name"]) > 13 else item["name"]
1371
+ price_s = format(item["current_price"], ",") + "원"
1372
+ items_html += f"""
1373
+ <div class="alert-row">
1374
+ <div class="alert-ticker-sq" style="background:{tc['bg']}; border:1px solid {tc['border']}; color:{tc['accent']};">
1375
+ {item['ticker'][:4]}
1376
+ </div>
1377
+ <div style="flex:1; min-width:0;">
1378
+ <div style="font-size:12px; font-weight:700; color:#e8eaf0; margin-bottom:1px;">
1379
+ {item['ticker']} <span style="font-size:10px; color:rgba(255,255,255,0.35); font-weight:400;">{nm}</span>
1380
+ </div>
1381
+ <div style="font-size:11px; color:rgba(255,255,255,0.4);">{price_s}</div>
1382
+ </div>
1383
+ <div style="text-align:right; flex-shrink:0;">
1384
+ <div style="font-size:12px; font-weight:700; color:{tc['accent']}; font-family:'JetBrains Mono',monospace;">{pct_str}</div>
1385
+ <div style="font-size:10px; color:rgba(255,255,255,0.25); margin-top:1px;">β†’ 뢄석</div>
1386
+ </div>
1387
+ </div>"""
1388
 
1389
+ if not items_html:
1390
+ items_html = '<div style="text-align:center; padding:22px; color:rgba(255,255,255,0.2); font-size:13px;">μ•ŒλžŒ μ—†μŒ</div>'
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1391
 
1392
+ # νŒ¨λ„ 전체 HTML
1393
+ st.markdown(f"""
1394
+ <div class="alert-float-wrap" style="animation: alertSlideUp 0.4s cubic-bezier(0.34,1.56,0.64,1);">
1395
+
1396
+ <!-- 헀더 -->
1397
+ <div class="alert-panel-hdr">
1398
+ <div class="alert-hdr-row">
1399
+ <div style="display:flex; align-items:center; gap:7px;">
1400
+ <span style="width:7px; height:7px; border-radius:50%; background:#FF6B35;
1401
+ box-shadow:0 0 7px rgba(255,107,53,0.8); animation:alertPulse 1.5s infinite; display:inline-block;"></span>
1402
+ <span style="font-size:12px; font-weight:700; color:#e8eaf0; letter-spacing:.08em; font-family:'JetBrains Mono',monospace;">LIVE ALERTS</span>
1403
+ <span style="background:rgba(229,62,62,0.15); border:1px solid rgba(229,62,62,0.3);
1404
+ border-radius:5px; padding:1px 7px; font-size:10px; color:#E53E3E; font-weight:700;">{total_cnt}</span>
1405
+ </div>
1406
+ <span style="font-size:11px; color:rgba(255,255,255,0.3); font-family:'JetBrains Mono',monospace;">탭을 눌러 μ „ν™˜</span>
1407
+ </div>
1408
+ <!-- νƒ­ -->
1409
+ <div class="alert-tabs">{tabs_html}</div>
1410
+ </div>
1411
 
1412
+ <!-- λ°”λ”” -->
1413
+ <div class="alert-panel-body" style="border-top: 2px solid {tc['accent']};">
1414
+ {items_html}
1415
+ </div>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1416
 
1417
+ </div>
1418
+ """, unsafe_allow_html=True)
 
 
 
 
1419
 
1420
+ # ── Streamlit λ²„νŠΌλ“€ (투λͺ… μ˜€λ²„λ ˆμ΄λ‘œ νƒ­/μ’…λͺ©/μ΅œμ†Œν™” 처리) ──
1421
 
1422
+ # μ΅œμ†Œν™” λ²„νŠΌ
1423
+ st.markdown("""
1424
+ <style>
1425
+ .alert-min-btn > div.stButton > button {
1426
+ position: fixed !important;
1427
+ bottom: 76px !important;
1428
+ right: 16px !important;
1429
+ width: 360px !important;
1430
+ height: 44px !important;
1431
+ opacity: 0 !important;
1432
+ cursor: pointer !important;
1433
+ z-index: 999999 !important;
1434
+ background: transparent !important;
1435
+ border: none !important;
1436
  }
1437
+ </style>
1438
+ <div class="alert-min-btn">
1439
+ """, unsafe_allow_html=True)
1440
+ if st.button("νŒ¨λ„μ΅œμ†Œν™”", key="alert_min_btn"):
1441
+ st.session_state.alert_panel_minimized = True
1442
+ st.rerun()
1443
+ st.markdown("</div>", unsafe_allow_html=True)
1444
+
1445
+ # νƒ­ μ „ν™˜ λ²„νŠΌλ“€
1446
+ tab_list = list(TAB_CFG.keys())
1447
+ tab_w = 360 // len(tab_list)
1448
+ for i, tab_name in enumerate(tab_list):
1449
+ left_px = 16 + i * tab_w
1450
+ btn_key = f"alert_tab_{tab_name}"
1451
+ st.markdown(f"""
1452
+ <style>
1453
+ .alert-tab-btn-{i} > div.stButton > button {{
1454
+ position: fixed !important;
1455
+ bottom: 138px !important;
1456
+ left: {left_px}px !important;
1457
+ width: {tab_w}px !important;
1458
+ height: 52px !important;
1459
+ opacity: 0 !important;
1460
+ cursor: pointer !important;
1461
+ z-index: 999999 !important;
1462
+ background: transparent !important;
1463
+ border: none !important;
1464
+ }}
1465
+ </style>
1466
+ <div class="alert-tab-btn-{i}">
1467
+ """, unsafe_allow_html=True)
1468
+ if st.button(tab_name, key=btn_key):
1469
+ st.session_state.alert_active_tab = tab_name
1470
+ st.rerun()
1471
+ st.markdown("</div>", unsafe_allow_html=True)
1472
+
1473
+ # μ’…λͺ© 클릭 λ²„νŠΌλ“€
1474
+ for j, item in enumerate(groups[active_tab]):
1475
+ tk = item["ticker"]
1476
+ row_top = 76 + 44 + 52 + j * 52 # λŒ€λž΅μ μΈ 각 μ•„μ΄ν…œ μœ„μΉ˜
1477
+ btn_key = f"alert_item_{active_tab}_{tk}_{j}"
1478
+ st.markdown(f"""
1479
+ <style>
1480
+ .alert-item-btn-{j} > div.stButton > button {{
1481
+ position: fixed !important;
1482
+ bottom: {76 + (len(groups[active_tab]) - 1 - j) * 52}px !important;
1483
+ right: 16px !important;
1484
+ width: 360px !important;
1485
+ height: 50px !important;
1486
+ opacity: 0 !important;
1487
+ cursor: pointer !important;
1488
+ z-index: 999999 !important;
1489
+ background: transparent !important;
1490
+ border: none !important;
1491
+ }}
1492
+ </style>
1493
+ <div class="alert-item-btn-{j}">
1494
+ """, unsafe_allow_html=True)
1495
+ if st.button(tk, key=btn_key):
1496
+ _navigate_to_ticker(tk)
1497
+ st.rerun()
1498
+ st.markdown("</div>", unsafe_allow_html=True)
1499
 
1500
 
1501
  # ============================================================
 
2079
  with nc[1]: st.button("*βŒ‚*\nν™ˆ", key="nav_home", on_click=go_home, use_container_width=True)
2080
  with nc[2]: st.button("*β˜…*\n관심", key="nav_fav", on_click=lambda: select_menu("β˜… 관심 μ’…λͺ©"), use_container_width=True)
2081
  with nc[3]: st.button("*β€Ή*\nλ’€λ‘œ", key="nav_back", on_click=go_back, use_container_width=True)