eshan6704 commited on
Commit
e9f68d4
·
verified ·
1 Parent(s): 58b5a46

Update app/router.py

Browse files
Files changed (1) hide show
  1. app/router.py +27 -4
app/router.py CHANGED
@@ -15,12 +15,15 @@ from . import bhavcopy_html as bhav
15
  from . import build_nse_fno as fno
16
  from . import nsepythonmodified as ns
17
  from . import yahooinfo
18
- from . import screener # screener owns its map
19
 
 
 
 
20
  router = APIRouter()
21
 
22
  # -------------------------------------------------------
23
- # REQ TYPE MAP (stock & index only)
24
  # -------------------------------------------------------
25
  REQ_TYPE_MAP = {
26
  "stock": [
@@ -39,12 +42,24 @@ REQ_TYPE_MAP = {
39
  ],
40
  }
41
 
 
 
 
 
 
 
 
 
 
 
 
42
  # -------------------------------------------------------
43
  # HTML builder for req_type discovery
44
  # -------------------------------------------------------
45
  def build_req_type_list_html():
46
  html = ["<div id='req_type_list'>"]
47
 
 
48
  for mode, items in REQ_TYPE_MAP.items():
49
  html.append(f"<h3>{mode.upper()}</h3><ul>")
50
  for it in items:
@@ -53,8 +68,9 @@ def build_req_type_list_html():
53
  )
54
  html.append("</ul>")
55
 
 
56
  html.append("<h3>SCREENER</h3><ul>")
57
- for key in screener.SCREENER_MAP.keys():
58
  html.append(
59
  f"<li class='screener-req' data-mode='screener'>{key}</li>"
60
  )
@@ -160,7 +176,13 @@ def handle_index(req: FetchRequest):
160
  # SCREENER handler
161
  # -------------------------------------------------------
162
  def handle_screener(req: FetchRequest):
163
- return screener.fetch_screener(req.req_type.lower())
 
 
 
 
 
 
164
 
165
  # -------------------------------------------------------
166
  # Routes
@@ -174,6 +196,7 @@ def fetch_data(req: FetchRequest):
174
 
175
  mode = req.mode.lower()
176
 
 
177
  if mode == "list":
178
  return HTMLResponse(content=build_req_type_list_html())
179
 
 
15
  from . import build_nse_fno as fno
16
  from . import nsepythonmodified as ns
17
  from . import yahooinfo
18
+ from . import screener # executor only
19
 
20
+ # -------------------------------------------------------
21
+ # Router
22
+ # -------------------------------------------------------
23
  router = APIRouter()
24
 
25
  # -------------------------------------------------------
26
+ # REQ TYPE MAP (stock & index)
27
  # -------------------------------------------------------
28
  REQ_TYPE_MAP = {
29
  "stock": [
 
42
  ],
43
  }
44
 
45
+ # -------------------------------------------------------
46
+ # SCREENER MAP (OWNER = ROUTER)
47
+ # -------------------------------------------------------
48
+ SCREENER_MAP = {
49
+ "from_high": "https://www.screener.in/screens/3355081/from-high/",
50
+ "sales_wise": "https://www.screener.in/screens/880780/sales_wise/",
51
+ "fii_buying": "https://www.screener.in/screens/343087/fii-buying/",
52
+ "debt_reduction": "https://www.screener.in/screens/126864/debt-reduction/",
53
+ "magic_formula": "https://www.screener.in/screens/59/magic-formula/",
54
+ }
55
+
56
  # -------------------------------------------------------
57
  # HTML builder for req_type discovery
58
  # -------------------------------------------------------
59
  def build_req_type_list_html():
60
  html = ["<div id='req_type_list'>"]
61
 
62
+ # STOCK & INDEX
63
  for mode, items in REQ_TYPE_MAP.items():
64
  html.append(f"<h3>{mode.upper()}</h3><ul>")
65
  for it in items:
 
68
  )
69
  html.append("</ul>")
70
 
71
+ # SCREENER
72
  html.append("<h3>SCREENER</h3><ul>")
73
+ for key in SCREENER_MAP.keys():
74
  html.append(
75
  f"<li class='screener-req' data-mode='screener'>{key}</li>"
76
  )
 
176
  # SCREENER handler
177
  # -------------------------------------------------------
178
  def handle_screener(req: FetchRequest):
179
+ key = req.req_type.lower()
180
+ url = SCREENER_MAP.get(key)
181
+
182
+ if not url:
183
+ return common.wrap(f"<h3>Invalid screener: {key}</h3>")
184
+
185
+ return screener.fetch_screener(url)
186
 
187
  # -------------------------------------------------------
188
  # Routes
 
196
 
197
  mode = req.mode.lower()
198
 
199
+ # frontend discovery call
200
  if mode == "list":
201
  return HTMLResponse(content=build_req_type_list_html())
202