Spaces:
Running
Running
Update app/screener.py
Browse files- app/screener.py +14 -6
app/screener.py
CHANGED
|
@@ -4,9 +4,17 @@ from bs4 import BeautifulSoup
|
|
| 4 |
from typing import List, Tuple
|
| 5 |
|
| 6 |
from . import persist
|
| 7 |
-
from . import router
|
| 8 |
-
|
| 9 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
|
| 11 |
# ===============================
|
| 12 |
# Public API
|
|
@@ -17,7 +25,8 @@ def fetch_screener(screen_name: str) -> str:
|
|
| 17 |
Uses disk persistence (HTML primary, CSV secondary).
|
| 18 |
"""
|
| 19 |
|
| 20 |
-
|
|
|
|
| 21 |
return _error_html(f"Invalid screener: {screen_name}")
|
| 22 |
|
| 23 |
cache_name = f"SCREENER_{screen_name.upper()}"
|
|
@@ -27,7 +36,7 @@ def fetch_screener(screen_name: str) -> str:
|
|
| 27 |
return persist.load(cache_name, "html")
|
| 28 |
|
| 29 |
# 2️⃣ Fetch live
|
| 30 |
-
headers, rows = _fetch_table(
|
| 31 |
|
| 32 |
if not headers or not rows:
|
| 33 |
return _error_html("No data available")
|
|
@@ -42,7 +51,6 @@ def fetch_screener(screen_name: str) -> str:
|
|
| 42 |
|
| 43 |
return html
|
| 44 |
|
| 45 |
-
|
| 46 |
# ===============================
|
| 47 |
# Internal helpers
|
| 48 |
# ===============================
|
|
@@ -137,4 +145,4 @@ def _error_html(msg: str) -> str:
|
|
| 137 |
">
|
| 138 |
❌ {msg}
|
| 139 |
</div>
|
| 140 |
-
"""
|
|
|
|
| 4 |
from typing import List, Tuple
|
| 5 |
|
| 6 |
from . import persist
|
|
|
|
|
|
|
| 7 |
|
| 8 |
+
# ===============================
|
| 9 |
+
# SCREENER MAP (OWNER)
|
| 10 |
+
# ===============================
|
| 11 |
+
SCREENER_MAP = {
|
| 12 |
+
"from_high": "https://www.screener.in/screens/3355081/from-high/",
|
| 13 |
+
"sales_wise": "https://www.screener.in/screens/880780/sales_wise/",
|
| 14 |
+
"fii_buying": "https://www.screener.in/screens/343087/fii-buying/",
|
| 15 |
+
"debt_reduction": "https://www.screener.in/screens/126864/debt-reduction/",
|
| 16 |
+
"magic_formula": "https://www.screener.in/screens/59/magic-formula/",
|
| 17 |
+
}
|
| 18 |
|
| 19 |
# ===============================
|
| 20 |
# Public API
|
|
|
|
| 25 |
Uses disk persistence (HTML primary, CSV secondary).
|
| 26 |
"""
|
| 27 |
|
| 28 |
+
url = SCREENER_MAP.get(screen_name)
|
| 29 |
+
if not url:
|
| 30 |
return _error_html(f"Invalid screener: {screen_name}")
|
| 31 |
|
| 32 |
cache_name = f"SCREENER_{screen_name.upper()}"
|
|
|
|
| 36 |
return persist.load(cache_name, "html")
|
| 37 |
|
| 38 |
# 2️⃣ Fetch live
|
| 39 |
+
headers, rows = _fetch_table(url)
|
| 40 |
|
| 41 |
if not headers or not rows:
|
| 42 |
return _error_html("No data available")
|
|
|
|
| 51 |
|
| 52 |
return html
|
| 53 |
|
|
|
|
| 54 |
# ===============================
|
| 55 |
# Internal helpers
|
| 56 |
# ===============================
|
|
|
|
| 145 |
">
|
| 146 |
❌ {msg}
|
| 147 |
</div>
|
| 148 |
+
"""
|