Update streamlit_app.py
Browse files- streamlit_app.py +53 -7
streamlit_app.py
CHANGED
|
@@ -17,17 +17,46 @@ TV_SELECTORS: List[str] = [
|
|
| 17 |
"div[class*='chart-page']",
|
| 18 |
]
|
| 19 |
|
| 20 |
-
# Minimal CSS to hide
|
| 21 |
# Applied only in Page mode - Snapshot mode (Alt+S) already provides clean output
|
| 22 |
HIDE_TV_CSS = '''
|
| 23 |
-
/*
|
| 24 |
[role="dialog"],
|
|
|
|
|
|
|
| 25 |
div[class*="paywall"],
|
| 26 |
div[class*="trial"],
|
| 27 |
div[class*="subscription"],
|
| 28 |
div[class*="popup"]:not([class*="chart"]):not([id*="chart"]) {
|
| 29 |
display:none !important; visibility:hidden !important; opacity:0 !important;
|
| 30 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 31 |
'''
|
| 32 |
|
| 33 |
def crop_png(png_bytes: bytes, box: Dict[str, float], pad: int = 8) -> bytes:
|
|
@@ -68,20 +97,37 @@ async def best_effort_close_popups(page) -> None:
|
|
| 68 |
except Exception:
|
| 69 |
pass
|
| 70 |
|
|
|
|
| 71 |
close_selectors = [
|
| 72 |
"button[aria-label='Close']",
|
| 73 |
"button[title='Close']",
|
| 74 |
-
"div[role='dialog'] button",
|
|
|
|
|
|
|
|
|
|
| 75 |
".close, .tv-dialog__close, .popupDialogButtonClose",
|
| 76 |
]
|
| 77 |
for sel in close_selectors:
|
| 78 |
try:
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
|
|
|
|
|
|
|
|
|
| 83 |
except Exception:
|
| 84 |
continue
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 85 |
|
| 86 |
async def wait_for_chart_stable(page, ms: int) -> None:
|
| 87 |
await page.wait_for_timeout(ms)
|
|
|
|
| 17 |
"div[class*='chart-page']",
|
| 18 |
]
|
| 19 |
|
| 20 |
+
# Minimal CSS to hide obvious UI elements without hitting the chart
|
| 21 |
# Applied only in Page mode - Snapshot mode (Alt+S) already provides clean output
|
| 22 |
HIDE_TV_CSS = '''
|
| 23 |
+
/* --- POPUPS & MODALS --- */
|
| 24 |
[role="dialog"],
|
| 25 |
+
div[class*="tv-dialog"],
|
| 26 |
+
div[class*="gopro-"],
|
| 27 |
div[class*="paywall"],
|
| 28 |
div[class*="trial"],
|
| 29 |
div[class*="subscription"],
|
| 30 |
div[class*="popup"]:not([class*="chart"]):not([id*="chart"]) {
|
| 31 |
display:none !important; visibility:hidden !important; opacity:0 !important;
|
| 32 |
}
|
| 33 |
+
|
| 34 |
+
/* --- SIDEBARS (Safe Selectors) --- */
|
| 35 |
+
/* Hide the right-hand widget sidebar */
|
| 36 |
+
div[class*="widgetbar"]:not([class*="chart"]),
|
| 37 |
+
div[class*="right-toolbar"]:not([class*="chart"]),
|
| 38 |
+
div[data-role="right-toolbar"],
|
| 39 |
+
aside[class*="sidebar"] {
|
| 40 |
+
display:none !important; visibility:hidden !important; opacity:0 !important;
|
| 41 |
+
}
|
| 42 |
+
|
| 43 |
+
/* --- HEADERS (Safe Selectors) --- */
|
| 44 |
+
/* Hide top navigation headers */
|
| 45 |
+
header:not([class*="chart"]),
|
| 46 |
+
div[class*="header"]:not([class*="chart"]):not([id*="chart"]):not([class*="pane"]),
|
| 47 |
+
div[class*="topbar"]:not([class*="chart"]) {
|
| 48 |
+
display:none !important; visibility:hidden !important; opacity:0 !important;
|
| 49 |
+
}
|
| 50 |
+
|
| 51 |
+
/* --- TRADINGVIEW SPECIFIC --- */
|
| 52 |
+
/* Hide floating drawing toolbars if possible, but be careful */
|
| 53 |
+
div[class*="drawing-toolbar"],
|
| 54 |
+
div[data-role="drawing-toolbar"] {
|
| 55 |
+
display:none !important; visibility:hidden !important; opacity:0 !important;
|
| 56 |
+
}
|
| 57 |
+
|
| 58 |
+
/* Hide legend if user wants pure chart (optional, usually kept but can start clutter) */
|
| 59 |
+
/* div[data-name="legend"] { display:none !important; } */
|
| 60 |
'''
|
| 61 |
|
| 62 |
def crop_png(png_bytes: bytes, box: Dict[str, float], pad: int = 8) -> bytes:
|
|
|
|
| 97 |
except Exception:
|
| 98 |
pass
|
| 99 |
|
| 100 |
+
# selectors for various close buttons
|
| 101 |
close_selectors = [
|
| 102 |
"button[aria-label='Close']",
|
| 103 |
"button[title='Close']",
|
| 104 |
+
"div[role='dialog'] button[class*='close']",
|
| 105 |
+
"div[class*='tv-dialog'] button",
|
| 106 |
+
"svg[class*='close-']", # Click SVGs that look like close icons
|
| 107 |
+
"[data-name='close']",
|
| 108 |
".close, .tv-dialog__close, .popupDialogButtonClose",
|
| 109 |
]
|
| 110 |
for sel in close_selectors:
|
| 111 |
try:
|
| 112 |
+
# Try clicking multiple times if there are multiple overlays
|
| 113 |
+
buttons = page.locator(sel)
|
| 114 |
+
count = await buttons.count()
|
| 115 |
+
for i in range(count):
|
| 116 |
+
if await buttons.nth(i).is_visible():
|
| 117 |
+
await buttons.nth(i).click(timeout=500)
|
| 118 |
+
await page.wait_for_timeout(200)
|
| 119 |
except Exception:
|
| 120 |
continue
|
| 121 |
+
|
| 122 |
+
# Explicitly try to close Gopro/Trial popups by finding "Maybe later" or "NO" buttons
|
| 123 |
+
deny_text_selectors = ["text=Maybe later", "text=No thanks", "text=Cancel"]
|
| 124 |
+
for txt in deny_text_selectors:
|
| 125 |
+
try:
|
| 126 |
+
btn = page.locator(txt).first
|
| 127 |
+
if await btn.is_visible():
|
| 128 |
+
await btn.click(timeout=500)
|
| 129 |
+
except Exception:
|
| 130 |
+
pass
|
| 131 |
|
| 132 |
async def wait_for_chart_stable(page, ms: int) -> None:
|
| 133 |
await page.wait_for_timeout(ms)
|