Spaces:
Sleeping
Sleeping
Update bhavcopy_html.py
Browse files- bhavcopy_html.py +21 -11
bhavcopy_html.py
CHANGED
|
@@ -17,7 +17,6 @@ def build_bhavcopy_html(date_str):
|
|
| 17 |
try:
|
| 18 |
df = nse_bhavcopy(date_str) # <-- your custom loader
|
| 19 |
df.columns = df.columns.str.strip()
|
| 20 |
-
|
| 21 |
except:
|
| 22 |
return f"<h3>No Bhavcopy found for {date_str}.</h3>"
|
| 23 |
|
|
@@ -52,17 +51,21 @@ def build_bhavcopy_html(date_str):
|
|
| 52 |
.str.strip()
|
| 53 |
)
|
| 54 |
df[col] = pd.to_numeric(df[col], errors="coerce").fillna(0)
|
| 55 |
-
|
| 56 |
-
|
|
|
|
| 57 |
# -------------------------------------------------------
|
| 58 |
-
|
|
|
|
|
|
|
|
|
|
| 59 |
# -------------------------------------------------------
|
| 60 |
df["change"] = df["CLOSE_PRICE"] - df["PREV_CLOSE"]
|
| 61 |
df["perchange"] = (df["change"] / df["PREV_CLOSE"].replace(0, 1)) * 100
|
| 62 |
df["pergap"] = ((df["OPEN_PRICE"] - df["PREV_CLOSE"]) / df["PREV_CLOSE"].replace(0, 1)) * 100
|
| 63 |
|
| 64 |
# -------------------------------------------------------
|
| 65 |
-
#
|
| 66 |
# -------------------------------------------------------
|
| 67 |
main_html = f"""
|
| 68 |
<div class="main-table-container">
|
|
@@ -71,7 +74,7 @@ def build_bhavcopy_html(date_str):
|
|
| 71 |
"""
|
| 72 |
|
| 73 |
# -------------------------------------------------------
|
| 74 |
-
#
|
| 75 |
# -------------------------------------------------------
|
| 76 |
metrics = ["perchange", "pergap", "TURNOVER_LACS", "NO_OF_TRADES", "DELIV_PER"]
|
| 77 |
existing_metrics = [m for m in metrics if m in df.columns]
|
|
@@ -95,7 +98,7 @@ def build_bhavcopy_html(date_str):
|
|
| 95 |
"""
|
| 96 |
|
| 97 |
# -------------------------------------------------------
|
| 98 |
-
#
|
| 99 |
# -------------------------------------------------------
|
| 100 |
css = """
|
| 101 |
<style>
|
|
@@ -126,20 +129,27 @@ def build_bhavcopy_html(date_str):
|
|
| 126 |
width: 100%;
|
| 127 |
}
|
| 128 |
th, td {
|
| 129 |
-
padding:
|
| 130 |
border: 1px solid #ddd;
|
| 131 |
}
|
| 132 |
th {
|
| 133 |
-
background: #
|
|
|
|
|
|
|
|
|
|
| 134 |
position: sticky;
|
| 135 |
top: 0;
|
| 136 |
-
z-index:
|
|
|
|
|
|
|
|
|
|
|
|
|
| 137 |
}
|
| 138 |
</style>
|
| 139 |
"""
|
| 140 |
|
| 141 |
# -------------------------------------------------------
|
| 142 |
-
#
|
| 143 |
# -------------------------------------------------------
|
| 144 |
return (
|
| 145 |
css +
|
|
|
|
| 17 |
try:
|
| 18 |
df = nse_bhavcopy(date_str) # <-- your custom loader
|
| 19 |
df.columns = df.columns.str.strip()
|
|
|
|
| 20 |
except:
|
| 21 |
return f"<h3>No Bhavcopy found for {date_str}.</h3>"
|
| 22 |
|
|
|
|
| 51 |
.str.strip()
|
| 52 |
)
|
| 53 |
df[col] = pd.to_numeric(df[col], errors="coerce").fillna(0)
|
| 54 |
+
|
| 55 |
+
# -------------------------------------------------------
|
| 56 |
+
# 5) Filter by turnover
|
| 57 |
# -------------------------------------------------------
|
| 58 |
+
df = df[df["TURNOVER_LACS"] > 1000]
|
| 59 |
+
|
| 60 |
+
# -------------------------------------------------------
|
| 61 |
+
# 6) Add computed columns
|
| 62 |
# -------------------------------------------------------
|
| 63 |
df["change"] = df["CLOSE_PRICE"] - df["PREV_CLOSE"]
|
| 64 |
df["perchange"] = (df["change"] / df["PREV_CLOSE"].replace(0, 1)) * 100
|
| 65 |
df["pergap"] = ((df["OPEN_PRICE"] - df["PREV_CLOSE"]) / df["PREV_CLOSE"].replace(0, 1)) * 100
|
| 66 |
|
| 67 |
# -------------------------------------------------------
|
| 68 |
+
# 7) MAIN TABLE (vertical scroll)
|
| 69 |
# -------------------------------------------------------
|
| 70 |
main_html = f"""
|
| 71 |
<div class="main-table-container">
|
|
|
|
| 74 |
"""
|
| 75 |
|
| 76 |
# -------------------------------------------------------
|
| 77 |
+
# 8) GRID TABLE (SYMBOL vs metric)
|
| 78 |
# -------------------------------------------------------
|
| 79 |
metrics = ["perchange", "pergap", "TURNOVER_LACS", "NO_OF_TRADES", "DELIV_PER"]
|
| 80 |
existing_metrics = [m for m in metrics if m in df.columns]
|
|
|
|
| 98 |
"""
|
| 99 |
|
| 100 |
# -------------------------------------------------------
|
| 101 |
+
# 9) CSS (improved header style)
|
| 102 |
# -------------------------------------------------------
|
| 103 |
css = """
|
| 104 |
<style>
|
|
|
|
| 129 |
width: 100%;
|
| 130 |
}
|
| 131 |
th, td {
|
| 132 |
+
padding: 4px 8px;
|
| 133 |
border: 1px solid #ddd;
|
| 134 |
}
|
| 135 |
th {
|
| 136 |
+
background: linear-gradient(to bottom, #4CAF50, #2E7D32);
|
| 137 |
+
color: white;
|
| 138 |
+
font-weight: bold;
|
| 139 |
+
text-align: center;
|
| 140 |
position: sticky;
|
| 141 |
top: 0;
|
| 142 |
+
z-index: 3;
|
| 143 |
+
box-shadow: 0 2px 2px -1px rgba(0,0,0,0.4);
|
| 144 |
+
}
|
| 145 |
+
td {
|
| 146 |
+
text-align: right;
|
| 147 |
}
|
| 148 |
</style>
|
| 149 |
"""
|
| 150 |
|
| 151 |
# -------------------------------------------------------
|
| 152 |
+
# 10) Final Output
|
| 153 |
# -------------------------------------------------------
|
| 154 |
return (
|
| 155 |
css +
|