eshan6704 commited on
Commit
f21a41e
·
verified ·
1 Parent(s): f97b685

Update index.py

Browse files
Files changed (1) hide show
  1. index.py +64 -1
index.py CHANGED
@@ -1,4 +1,4 @@
1
- import io
2
  import requests
3
  import pandas as pd
4
  import yfinance as yf
@@ -51,3 +51,66 @@ def fetch_index(max_rows=200):
51
 
52
  except Exception as e:
53
  return html_card("Error", str(e))
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ '''import io
2
  import requests
3
  import pandas as pd
4
  import yfinance as yf
 
51
 
52
  except Exception as e:
53
  return html_card("Error", str(e))
54
+ '''
55
+ import io
56
+ import requests
57
+ import pandas as pd
58
+ import yfinance as yf
59
+ from datetime import datetime, timedelta
60
+
61
+ from common import html_card, wrap_html
62
+ from ta_indi_pat import talib_df
63
+ import datetime
64
+ from nse import nse_index_df
65
+
66
+
67
+ def fetch_index(max_rows=200):
68
+ """
69
+ Fetch NIFTY 50 data using nse_index_df(),
70
+ format each returned DataFrame into its own HTML table.
71
+ """
72
+
73
+ try:
74
+ # ------------------------------------------------
75
+ # Fetch NIFTY 50 → 4 dataframes
76
+ # ------------------------------------------------
77
+ df_market, df_adv, df_meta, df_data = nse_index_df(index_name="NIFTY 50")
78
+
79
+ # Debug print
80
+ print("MARKET DF:", df_market.shape)
81
+ print("ADVANCE DECLINE DF:", df_adv.shape)
82
+ print("META DF:", df_meta.shape)
83
+ print("DATA DF:", df_data.shape)
84
+
85
+ # ------------------------------------------------
86
+ # Helper for HTML conversion
87
+ # ------------------------------------------------
88
+ def make_table(df):
89
+ return f"""
90
+ <div style="overflow-x:auto; overflow-y:auto; max-height:450px; border:1px solid #ccc; padding:8px; margin-bottom:18px;">
91
+ {df.to_html(classes='table table-striped table-bordered', index=False)}
92
+ </div>
93
+ """
94
+
95
+ # Convert all tables
96
+ html_market = make_table(df_market)
97
+ html_adv = make_table(df_adv)
98
+ html_meta = make_table(df_meta)
99
+ html_data = make_table(df_data)
100
+
101
+ # ------------------------------------------------
102
+ # Final HTML layout
103
+ # ------------------------------------------------
104
+ content = f"""
105
+ <h2>NIFTY 50 - Index Report</h2>
106
+
107
+ {html_card("Market Overview", html_market)}
108
+ {html_card("Advance / Decline", html_adv)}
109
+ {html_card("Index Meta Information", html_meta)}
110
+ {html_card("Daily OHLCV + Calculated Indicators", html_data)}
111
+ """
112
+
113
+ return wrap_html(content, title="NIFTY 50 Index Data")
114
+
115
+ except Exception as e:
116
+ return html_card("Error", str(e))