eshan6704 commited on
Commit
71a405b
·
verified ·
1 Parent(s): c47b457

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +77 -35
app.py CHANGED
@@ -4,59 +4,101 @@ from nse import *
4
  from stock import *
5
 
6
 
7
-
8
-
9
- # -----------------------------
10
- # Data fetch function
11
- # -----------------------------
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
12
  def fetch_data(mode, req_type, name):
13
  req_type = req_type.lower()
14
  symbol = name
15
- if mode=="index":
16
- if req_type=="indices":
17
- return indices()
18
- elif req_type=="open":
19
- return open(name)
20
- elif req_type=="preopen":
21
- return preopen(name)
22
- elif req_type=="fno":
23
- return fno(name)
24
-
25
- elif mode=="stock":
26
-
 
 
 
 
 
 
 
 
27
  if req_type == "daily":
28
- return fetch_daily(symbol)
 
29
  elif req_type == "intraday":
30
- return fetch_intraday(symbol)
 
31
  elif req_type == "info":
32
- return fetch_info(symbol)
 
33
  elif req_type == "qresult":
34
- return fetch_qresult(symbol)
 
35
  elif req_type == "result":
36
- return fetch_result(symbol)
 
37
  elif req_type == "balance":
38
- return fetch_balance(symbol)
 
39
  elif req_type == "cashflow":
40
- return fetch_cashflow(symbol)
 
41
  elif req_type == "dividend":
42
- return fetch_dividend(symbol)
 
43
  elif req_type == "split":
44
- return fetch_split(symbol)
 
45
  elif req_type == "other":
46
- return fetch_other(symbol)
47
- else:
48
- return f"<h1>No handler for {req_type}</h1>"
 
49
 
 
50
 
51
- # -----------------------------
 
52
  # UI
53
- # -----------------------------
54
  with gr.Blocks(title="Stock / Index App") as iface:
55
 
56
  gr.Markdown("### **Stock / Index Data Fetcher**")
57
 
58
- # ----- Top bar -----
59
  with gr.Row():
 
60
  mode_input = gr.Textbox(
61
  label="Mode",
62
  value="stock",
@@ -83,14 +125,14 @@ with gr.Blocks(title="Stock / Index App") as iface:
83
 
84
  btn = gr.Button("Fetch", scale=1)
85
 
86
- # ----- Output -----
87
  output = gr.HTML(label="Output")
88
 
89
  btn.click(fetch_data, inputs=[mode_input, req_type, symbol], outputs=output)
90
 
91
 
92
- # -----------------------------
93
  # Launch
94
- # -----------------------------
95
  if __name__ == "__main__":
96
  iface.launch(server_name="0.0.0.0", server_port=7860)
 
4
  from stock import *
5
 
6
 
7
+ # ======================================================
8
+ # Scrollable HTML wrapper for all table-based output
9
+ # ======================================================
10
+ SCROLL_WRAP = """
11
+ <div style="
12
+ max-height: 80vh;
13
+ overflow-y: auto;
14
+ overflow-x: auto;
15
+ padding: 10px;
16
+ border: 1px solid #ccc;
17
+ border-radius: 6px;
18
+ ">
19
+ {{HTML}}
20
+ </div>
21
+ """
22
+
23
+
24
+ def wrap(html):
25
+ """Wrap returned HTML inside scrollable container"""
26
+ if html is None:
27
+ return "<h3>No Data</h3>"
28
+ return SCROLL_WRAP.replace("{{HTML}}", html)
29
+
30
+
31
+ # ======================================================
32
+ # Data Fetcher
33
+ # ======================================================
34
  def fetch_data(mode, req_type, name):
35
  req_type = req_type.lower()
36
  symbol = name
37
+
38
+ if mode == "index":
39
+
40
+ if req_type == "indices":
41
+ return wrap(indices())
42
+
43
+ elif req_type == "open":
44
+ return wrap(open(name))
45
+
46
+ elif req_type == "preopen":
47
+ return wrap(preopen(name))
48
+
49
+ elif req_type == "fno":
50
+ return wrap(fno(name))
51
+
52
+ else:
53
+ return wrap(f"<h3>No handler for {req_type}</h3>")
54
+
55
+ elif mode == "stock":
56
+
57
  if req_type == "daily":
58
+ return wrap(fetch_daily(symbol))
59
+
60
  elif req_type == "intraday":
61
+ return wrap(fetch_intraday(symbol))
62
+
63
  elif req_type == "info":
64
+ return wrap(fetch_info(symbol))
65
+
66
  elif req_type == "qresult":
67
+ return wrap(fetch_qresult(symbol))
68
+
69
  elif req_type == "result":
70
+ return wrap(fetch_result(symbol))
71
+
72
  elif req_type == "balance":
73
+ return wrap(fetch_balance(symbol))
74
+
75
  elif req_type == "cashflow":
76
+ return wrap(fetch_cashflow(symbol))
77
+
78
  elif req_type == "dividend":
79
+ return wrap(fetch_dividend(symbol))
80
+
81
  elif req_type == "split":
82
+ return wrap(fetch_split(symbol))
83
+
84
  elif req_type == "other":
85
+ return wrap(fetch_other(symbol))
86
+
87
+ else:
88
+ return wrap(f"<h3>No handler for {req_type}</h3>")
89
 
90
+ return wrap(f"<h3>No valid mode: {mode}</h3>")
91
 
92
+
93
+ # ======================================================
94
  # UI
95
+ # ======================================================
96
  with gr.Blocks(title="Stock / Index App") as iface:
97
 
98
  gr.Markdown("### **Stock / Index Data Fetcher**")
99
 
 
100
  with gr.Row():
101
+
102
  mode_input = gr.Textbox(
103
  label="Mode",
104
  value="stock",
 
125
 
126
  btn = gr.Button("Fetch", scale=1)
127
 
128
+ # Output box (scroll handled by wrapper)
129
  output = gr.HTML(label="Output")
130
 
131
  btn.click(fetch_data, inputs=[mode_input, req_type, symbol], outputs=output)
132
 
133
 
134
+ # ======================================================
135
  # Launch
136
+ # ======================================================
137
  if __name__ == "__main__":
138
  iface.launch(server_name="0.0.0.0", server_port=7860)