eshan6704 commited on
Commit
d945346
·
verified ·
1 Parent(s): e13df2b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +44 -6
app.py CHANGED
@@ -6,6 +6,7 @@ from preopen_html import *
6
  from eq_html import *
7
  import pandas as pd
8
  from bhavcopy_html import *
 
9
 
10
  # ======================================================
11
  # Scrollable HTML wrapper
@@ -23,6 +24,16 @@ SCROLL_WRAP = """
23
  </div>
24
  """
25
 
 
 
 
 
 
 
 
 
 
 
26
  def wrap(html):
27
  if html is None:
28
  return "<h3>No Data</h3>"
@@ -34,12 +45,13 @@ def wrap(html):
34
  # ======================================================
35
  STOCK_REQ = [
36
  "info", "intraday", "daily","nse_eq", "qresult", "result", "balance",
37
- "cashflow", "dividend", "split", "other"
38
  ]
39
 
40
  INDEX_REQ = [
41
- "indices", "nse_open", "nse_preopen", "nse_fno",
42
- "nse_future", "nse_bhav", "nse_highlow"
 
43
  ]
44
 
45
 
@@ -61,7 +73,7 @@ def fetch_data(mode, req_type, name, date_str):
61
  req_type = req_type.lower()
62
  name = name.strip()
63
  date_str = date_str.strip()
64
-
65
  if mode == "index":
66
  if req_type == "indices":
67
  return build_indices_html()
@@ -72,12 +84,36 @@ def fetch_data(mode, req_type, name, date_str):
72
  return build_preopen_html()
73
  elif req_type == "nse_fno":
74
  return wrap(nse_fno(name))
 
 
 
 
75
  elif req_type == "nse_future":
76
  return wrap(nse_future(name))
77
- elif req_type == "nse_bhav":
78
- return build_bhavcopy_html(date_str) # no default
79
  elif req_type == "nse_highlow":
80
  return wrap(nse_highlow())
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
81
  else:
82
  return wrap(f"<h3>No handler for {req_type}</h3>")
83
 
@@ -104,6 +140,8 @@ def fetch_data(mode, req_type, name, date_str):
104
  return wrap(fetch_split(name))
105
  elif req_type == "other":
106
  return wrap(fetch_other(name))
 
 
107
  else:
108
  return wrap(f"<h3>No handler for {req_type}</h3>")
109
 
 
6
  from eq_html import *
7
  import pandas as pd
8
  from bhavcopy_html import *
9
+ from nsepython import *
10
 
11
  # ======================================================
12
  # Scrollable HTML wrapper
 
24
  </div>
25
  """
26
 
27
+ import datetime
28
+
29
+ def last_year_date(d):
30
+ # d = "09-12-2025"
31
+ dt = datetime.datetime.strptime(d, "%d-%m-%Y")
32
+ new_dt = dt.replace(year=dt.year - 1)
33
+ return new_dt.strftime("%d-%m-%Y")
34
+
35
+
36
+
37
  def wrap(html):
38
  if html is None:
39
  return "<h3>No Data</h3>"
 
45
  # ======================================================
46
  STOCK_REQ = [
47
  "info", "intraday", "daily","nse_eq", "qresult", "result", "balance",
48
+ "cashflow", "dividend", "split", "other","stock_hist"
49
  ]
50
 
51
  INDEX_REQ = [
52
+ "indices", "nse_open", "nse_preopen", "nse_fno","nse_fiidii","nse_events"
53
+ "nse_future", "nse_bhav", "nse_highlow","index_history","nse_largedeals","nse_most_active","largedeals_historical","nse_bulkdeals",
54
+ "nse_blockdeals","index_pe_pb_div","index_total_returns"
55
  ]
56
 
57
 
 
73
  req_type = req_type.lower()
74
  name = name.strip()
75
  date_str = date_str.strip()
76
+ date_start= last_year_date(date_str)
77
  if mode == "index":
78
  if req_type == "indices":
79
  return build_indices_html()
 
84
  return build_preopen_html()
85
  elif req_type == "nse_fno":
86
  return wrap(nse_fno(name))
87
+ elif req_type == "nse_events":
88
+ return nse_events().to_html()
89
+ elif req_type == "nse_fiidii":
90
+ return nse_fiidii().to_html()
91
  elif req_type == "nse_future":
92
  return wrap(nse_future(name))
 
 
93
  elif req_type == "nse_highlow":
94
  return wrap(nse_highlow())
95
+ elif req_type == "nse_bhav":
96
+ return build_bhavcopy_html(date_str) # no default
97
+ elif req_type == "nse_largedeals":
98
+ return nse_largedeals().to_html()
99
+ elif req_type == "nse_bulkdeals":
100
+ return nse_bulkdeals().to_html()
101
+
102
+ elif req_type == "nse_blockdeals":
103
+ return nse_blockdeals().to_html()
104
+ elif req_type == "nse_most_active":
105
+ return nse_most_active().to_html()
106
+ elif req_type == "index_history":
107
+ return index_history("NIFTY 50",date_start,date_str).to_html() # no default
108
+ elif req_type == "largedeals_historical":
109
+ return nse_largedeals_historical(date_start,date_str).to_html() # no default
110
+ elif req_type == "index_pe_pb_div":
111
+ return index_pe_pb_div("NIFY 50",date_start,date_str).to_html() # no default
112
+ elif req_type == "index_total_returns":
113
+ return index_total_returns("NIFY 50",date_start,date_str).to_html() # no default
114
+
115
+ nse_largedeals_historical
116
+
117
  else:
118
  return wrap(f"<h3>No handler for {req_type}</h3>")
119
 
 
140
  return wrap(fetch_split(name))
141
  elif req_type == "other":
142
  return wrap(fetch_other(name))
143
+ elif req_type == "stock_hist":
144
+ return nse_stock_hist(date_start,date_str,name).to_html()
145
  else:
146
  return wrap(f"<h3>No handler for {req_type}</h3>")
147