Spaces:
Sleeping
Sleeping
Update nse.py
Browse files
nse.py
CHANGED
|
@@ -78,17 +78,30 @@ def fetch_stock_df(nse_module, stock, start, end, series="ALL"):
|
|
| 78 |
# ---------------------------------------------------
|
| 79 |
# All NSE Indices → DataFrames
|
| 80 |
# ---------------------------------------------------
|
| 81 |
-
def
|
| 82 |
url = "https://www.nseindia.com/api/allIndices"
|
| 83 |
data = fetch_data(url)
|
| 84 |
if data is None:
|
| 85 |
-
return None
|
| 86 |
|
|
|
|
| 87 |
df_dates = pd.DataFrame([data["dates"]])
|
| 88 |
df_meta = pd.DataFrame([{k: v for k, v in data.items() if k not in ["data", "dates"]}])
|
| 89 |
df_data = pd.DataFrame(data["data"])
|
| 90 |
|
| 91 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 92 |
|
| 93 |
# ---------------------------------------------------
|
| 94 |
# Specific Index → DataFrames
|
|
|
|
| 78 |
# ---------------------------------------------------
|
| 79 |
# All NSE Indices → DataFrames
|
| 80 |
# ---------------------------------------------------
|
| 81 |
+
def indices():
|
| 82 |
url = "https://www.nseindia.com/api/allIndices"
|
| 83 |
data = fetch_data(url)
|
| 84 |
if data is None:
|
| 85 |
+
return None
|
| 86 |
|
| 87 |
+
# DataFrames
|
| 88 |
df_dates = pd.DataFrame([data["dates"]])
|
| 89 |
df_meta = pd.DataFrame([{k: v for k, v in data.items() if k not in ["data", "dates"]}])
|
| 90 |
df_data = pd.DataFrame(data["data"])
|
| 91 |
|
| 92 |
+
# Convert to HTML pieces
|
| 93 |
+
html_dates = df_dates.to_html(index=False, border=1)
|
| 94 |
+
html_meta = df_meta.to_html(index=False, border=1)
|
| 95 |
+
html_data = df_data.to_html(index=False, border=1)
|
| 96 |
+
|
| 97 |
+
# Combine into one single HTML block
|
| 98 |
+
full_html = (
|
| 99 |
+
"<h3>Dates</h3>" + html_dates +
|
| 100 |
+
"<br><h3>Meta</h3>" + html_meta +
|
| 101 |
+
"<br><h3>Data</h3>" + html_data
|
| 102 |
+
)
|
| 103 |
+
|
| 104 |
+
return full_html
|
| 105 |
|
| 106 |
# ---------------------------------------------------
|
| 107 |
# Specific Index → DataFrames
|