eshan6704 commited on
Commit
bb2645d
·
verified ·
1 Parent(s): 8899a10

Update daily.py

Browse files
Files changed (1) hide show
  1. daily.py +28 -26
daily.py CHANGED
@@ -1,35 +1,37 @@
1
  # daily.py
2
  import yfinance as yf
3
- import pandas as pd
4
  from chart_builder import build_chart
5
 
6
- def fetch_daily(symbol):
7
- yfs = f"{symbol}.NS"
8
- df = yf.download(yfs, period="1y", interval="1d").round(2)
9
 
10
- if df.empty:
11
- return {
12
- "html": f"<h1>No daily data for {symbol}</h1>",
13
- "data": {}
14
- }
 
 
 
 
 
15
 
16
- chart_html = build_chart(df)
 
 
17
 
18
- table_html = df.tail(30).to_html(
19
- classes="styled-table",
20
- border=0
21
- )
22
 
23
- final = f"""
24
- <div class="group">
25
- <h2>Daily Chart — {symbol}</h2>
26
- {chart_html}
27
- <h3>Last 30 Days Data</h3>
28
- {table_html}
29
- </div>
30
- """
31
 
32
- return {
33
- "html": final,
34
- "data": df.tail(30).to_dict()
35
- }
 
1
  # daily.py
2
  import yfinance as yf
3
+ from common import wrap_html, make_table
4
  from chart_builder import build_chart
5
 
6
+ # ============================================================
7
+ # DAILY DATA PROCESSING
8
+ # ============================================================
9
 
10
+ def fetch_daily(symbol, indicators=None):
11
+ """
12
+ Fetch daily data for 1 year, apply indicators, and return full HTML.
13
+ """
14
+ yfsymbol = f"{symbol}.NS"
15
+ try:
16
+ # Fetch 1-year daily data
17
+ df = yf.download(yfsymbol, period="1y", interval="1d").round(2)
18
+ if df.empty:
19
+ return wrap_html(f"<h1>No daily data available for {symbol}</h1>")
20
 
21
+ # Reset MultiIndex if exists
22
+ if isinstance(df.columns, pd.MultiIndex):
23
+ df.columns = df.columns.get_level_values(0)
24
 
25
+ # Build chart with optional indicators
26
+ chart_html = build_chart(df, indicators=indicators, volume=True)
 
 
27
 
28
+ # Format last 30 rows for table
29
+ table_html = make_table(df.tail(30))
30
+
31
+ # Wrap in full HTML
32
+ full_html = wrap_html(f"{chart_html}<h2>Recent Daily Data (last 30 rows)</h2>{table_html}",
33
+ title=f"Daily Data for {symbol}")
34
+ return full_html
 
35
 
36
+ except Exception as e:
37
+ return wrap_html(f"<h1>Error fetching daily data for {symbol}</h1><p>{str(e)}</p>")