File size: 4,357 Bytes
989249d
 
 
 
 
 
 
 
 
 
 
23337b4
989249d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
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 "<h3>Error: EQ data not available</h3>"

    # -------------------------------------------------------
    # Helper to convert DF β†’ HTML table
    # -------------------------------------------------------
    def df_to_table(df):
        if df is None or len(df) == 0:
            return '<div class="empty">No data</div>'
        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"""
        <div class="section">
            <div class="section-header">
                <div class="section-title">{sec}</div>
                <button class="toggle-btn" onclick="toggleSection('{sec}')">View / Hide</button>
            </div>
            <div id="{sec}" class="section-body">
                {df_to_table(df)}
            </div>
        </div>
        """

    # -------------------------------------------------------
    # FINAL HTML PAGE
    # -------------------------------------------------------
    html = f"""
    <html>
    <head>
    <style>
        body {{
            font-family: Arial, sans-serif;
            background: #fafafa;
            margin: 0;
            padding: 12px;
        }}
        h2 {{
            color: #0366d6;
            margin-bottom: 10px;
        }}
        .section {{
            background: #fff;
            border: 1px solid #ddd;
            margin-bottom: 14px;
            padding: 12px;
            border-radius: 6px;
        }}
        .section-header {{
            display: flex;
            justify-content: space-between;
            margin-bottom: 8px;
        }}
        .section-title {{
            font-weight: bold;
            color: #0b69a3;
            font-size: 15px;
        }}
        .toggle-btn {{
            background: #0b69a3;
            color: #fff;
            border: none;
            padding: 6px 10px;
            font-size: 12px;
            border-radius: 5px;
            cursor: pointer;
        }}
        .section-body {{
            margin-top: 6px;
        }}
        .tbl {{
            border-collapse: collapse;
            width: 100%;
            font-size: 13px;
        }}
        .tbl th {{
            background: #0b69a3;
            color: #fff;
            padding: 6px;
            border: 1px solid #ccc;
        }}
        .tbl td {{
            padding: 6px;
            border: 1px solid #ccc;
        }}
        .empty {{
            padding: 10px;
            color: #777;
        }}
    </style>

    <script>
    function toggleSection(id) {{
        let e = document.getElementById(id);
        if (e.style.display === "none") {{
            e.style.display = "block";
        }} else {{
            e.style.display = "none";
        }}
    }}
    </script>
    </head>

    <body>
        <h2>Equity Report β€” {symbol}</h2>

        {section_html}

    </body>
    </html>
    """

    return html