from nsepython import *
def build_eq_html(symbol):
"""Build full HTML page for eq(symbol) output, similar to build_indices_html."""
import json
import pandas as pd
# -------------------------------------------------------
# CALL eq() function internally
# -------------------------------------------------------
out = eq(symbol) # <-- your existing eq(symbol)
print(out)
if not isinstance(out, dict):
return "
Error: EQ data not available
"
# -------------------------------------------------------
# Helper to convert DF → HTML table
# -------------------------------------------------------
def df_to_table(df):
if df is None or len(df) == 0:
return 'No data
'
return df.to_html(index=False, escape=False, border=0, classes="tbl")
# -------------------------------------------------------
# ORDER — metadata FIRST (date table)
# -------------------------------------------------------
section_order = [
"metadata",
"securityInfo",
"priceInfo",
"industryInfo",
"pdSectorIndAll",
"info",
"preOpen",
"preOpenMarket"
]
# Normalize all values into DataFrame
normalized = {}
for sec in section_order:
val = out.get(sec, None)
if isinstance(val, pd.DataFrame):
normalized[sec] = val
elif isinstance(val, list):
normalized[sec] = pd.DataFrame(val)
elif isinstance(val, dict):
normalized[sec] = pd.DataFrame([val])
else:
normalized[sec] = pd.DataFrame()
# -------------------------------------------------------
# Build sections HTML
# -------------------------------------------------------
section_html = ""
for sec in section_order:
df = normalized[sec]
section_html += f"""
"""
# -------------------------------------------------------
# FINAL HTML PAGE
# -------------------------------------------------------
html = f"""
Equity Report — {symbol}
{section_html}
"""
return html