eshan6704 commited on
Commit
2d3723c
·
verified ·
1 Parent(s): d664639

Update daily.py

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