# info.py import yfinance as yf from common import format_large_number, format_timestamp_to_date def fetch_info(symbol): STYLE_BLOCK = """ """ yfsymbol = symbol + ".NS" content_html = "

No info available

" try: ticker = yf.Ticker(yfsymbol) info = ticker.info if info: long_summary = info.pop("longBusinessSummary", None) officers = info.pop("companyOfficers", None) info_categories = { "Company Overview": [ "longName", "symbol", "exchange", "quoteType", "sector", "industry", "fullTimeEmployees", "website", "address1", "city", "state", "zip", "country", "phone" ], "Valuation Metrics": [ "marketCap", "enterpriseValue", "trailingPE", "forwardPE", "pegRatio", "priceToSalesTrailing12Months", "enterpriseToRevenue", "enterpriseToEbitda" ], "Key Financials": [ "fiftyTwoWeekHigh", "fiftyTwoWeekLow", "fiftyDayAverage", "twoHundredDayAverage", "trailingAnnualDividendRate", "trailingAnnualDividendYield", "dividendRate", "dividendYield", "exDividendDate", "lastSplitFactor", "lastSplitDate", "lastDividendValue", "payoutRatio", "beta", "sharesOutstanding", "impliedSharesOutstanding" ], "Operational Details": [ "auditRisk", "boardRisk", "compensationRisk", "shareHolderRightsRisk", "overallRisk", "governanceEpochDate", "compensationAsOfEpochDate" ], "Trading Information": [ "open", "previousClose", "dayLow", "dayHigh", "volume", "averageVolume", "averageVolume10days", "fiftyTwoWeekChange", "SandP52WeekChange", "currency", "regularMarketDayLow", "regularMarketDayHigh", "regularMarketOpen", "regularMarketPreviousClose", "regularMarketPrice", "regularMarketVolume", "regularMarketChange", "regularMarketChangePercent" ], "Analyst & Target": [ "targetMeanPrice", "numberOfAnalystOpinions", "recommendationKey", "recommendationMean" ] } categorized_html = "" for category_name, keys in info_categories.items(): category_html = "" for key in keys: if key in info and info[key] not in [None, []]: value = info[key] if key in ["exDividendDate","lastSplitDate","governanceEpochDate","compensationAsOfEpochDate"]: value = format_timestamp_to_date(value) elif key in ["marketCap","enterpriseValue","fullTimeEmployees","volume","averageVolume","averageVolume10days","sharesOutstanding","impliedSharesOutstanding","regularMarketVolume"]: value = format_large_number(value) elif isinstance(value,(int,float)): if 'percent' in key.lower() or 'ratio' in key.lower() or 'yield' in key.lower() or 'beta' in key.lower() or 'payoutratio' in key.lower(): value = f"{value:.2%}" elif 'price' in key.lower() or 'dividend' in key.lower() or 'average' in key.lower(): value = f"{value:.2f}" else: value = f"{value:,.0f}" category_html += f"

{key.replace('_',' ').title()}

{value}

" if category_html: categorized_html += f"

{category_name}

{category_html}
" extra_sections = "" if long_summary: extra_sections += f"

Business Summary

{long_summary}

" if officers: officer_rows = "".join( f"{o.get('name','')}{o.get('title','')}{o.get('age','')}" for o in officers ) officer_table = f"{officer_rows}
NameTitleAge
" extra_sections += f"

Company Officers

{officer_table}
" content_html = f"{categorized_html}{extra_sections}" except Exception as e: content_html = f"

Error

{e}

" return f"{STYLE_BLOCK}{content_html}"