Update info.py
Browse files
info.py
CHANGED
|
@@ -1,97 +1,19 @@
|
|
| 1 |
# info.py
|
| 2 |
import yfinance as yf
|
| 3 |
-
from common import format_large_number, format_timestamp_to_date
|
| 4 |
|
| 5 |
def fetch_info(symbol):
|
| 6 |
-
|
| 7 |
-
<style>
|
| 8 |
-
.styled-table {
|
| 9 |
-
border-collapse: collapse;
|
| 10 |
-
margin: 10px 0;
|
| 11 |
-
font-size: 0.9em;
|
| 12 |
-
font-family: sans-serif;
|
| 13 |
-
width: 100%;
|
| 14 |
-
box-shadow: 0 0 10px rgba(0,0,0,0.1);
|
| 15 |
-
}
|
| 16 |
-
.styled-table th, .styled-table td {
|
| 17 |
-
padding: 8px 10px;
|
| 18 |
-
border: 1px solid #ddd;
|
| 19 |
-
}
|
| 20 |
-
.styled-table tbody tr:nth-child(even) {
|
| 21 |
-
background-color: #f9f9f9;
|
| 22 |
-
}
|
| 23 |
-
.card {
|
| 24 |
-
display: block;
|
| 25 |
-
width: 95%;
|
| 26 |
-
margin: 10px auto;
|
| 27 |
-
padding: 15px;
|
| 28 |
-
border: 1px solid #ddd;
|
| 29 |
-
border-radius: 8px;
|
| 30 |
-
box-shadow: 0 2px 5px rgba(0,0,0,0.1);
|
| 31 |
-
background: #fafafa;
|
| 32 |
-
}
|
| 33 |
-
.card-category-title {
|
| 34 |
-
font-size: 1.1em;
|
| 35 |
-
color: #222;
|
| 36 |
-
margin: 0 0 8px;
|
| 37 |
-
border-bottom: 1px solid #eee;
|
| 38 |
-
padding-bottom: 5px;
|
| 39 |
-
}
|
| 40 |
-
.card-content-grid {
|
| 41 |
-
display: flex;
|
| 42 |
-
flex-wrap: wrap;
|
| 43 |
-
gap: 15px;
|
| 44 |
-
}
|
| 45 |
-
.key-value-pair {
|
| 46 |
-
flex: 1 1 calc(20% - 15px);
|
| 47 |
-
box-sizing: border-box;
|
| 48 |
-
min-width: 150px;
|
| 49 |
-
background: #fff;
|
| 50 |
-
padding: 10px;
|
| 51 |
-
border: 1px solid #e0e0e0;
|
| 52 |
-
border-radius: 5px;
|
| 53 |
-
box-shadow: 0 1px 3px rgba(0,0,0,0.05);
|
| 54 |
-
}
|
| 55 |
-
.key-value-pair h3 {
|
| 56 |
-
font-size: 0.95em;
|
| 57 |
-
color: #444;
|
| 58 |
-
margin: 0 0 5px 0;
|
| 59 |
-
border-bottom: none;
|
| 60 |
-
padding-bottom: 0;
|
| 61 |
-
}
|
| 62 |
-
.key-value-pair p {
|
| 63 |
-
font-size: 0.9em;
|
| 64 |
-
color: #555;
|
| 65 |
-
margin: 0;
|
| 66 |
-
font-weight: bold;
|
| 67 |
-
}
|
| 68 |
-
.big-box {
|
| 69 |
-
width:95%;
|
| 70 |
-
margin:20px auto;
|
| 71 |
-
padding:20px;
|
| 72 |
-
border:1px solid #ccc;
|
| 73 |
-
border-radius:8px;
|
| 74 |
-
background:#fff;
|
| 75 |
-
box-shadow:0 2px 8px rgba(0,0,0,0.1);
|
| 76 |
-
font-size:0.95em;
|
| 77 |
-
line-height:1.4em;
|
| 78 |
-
max-height:400px;
|
| 79 |
-
overflow-y:auto;
|
| 80 |
-
}
|
| 81 |
-
</style>
|
| 82 |
-
"""
|
| 83 |
-
|
| 84 |
-
yfsymbol = symbol + ".NS"
|
| 85 |
-
content_html = "<h1>No info available</h1>"
|
| 86 |
-
|
| 87 |
try:
|
| 88 |
ticker = yf.Ticker(yfsymbol)
|
| 89 |
info = ticker.info
|
| 90 |
-
|
| 91 |
-
|
|
|
|
| 92 |
long_summary = info.pop("longBusinessSummary", None)
|
| 93 |
officers = info.pop("companyOfficers", None)
|
| 94 |
-
|
|
|
|
| 95 |
info_categories = {
|
| 96 |
"Company Overview": [
|
| 97 |
"longName", "symbol", "exchange", "quoteType", "sector", "industry",
|
|
@@ -124,30 +46,29 @@ def fetch_info(symbol):
|
|
| 124 |
|
| 125 |
categorized_html = ""
|
| 126 |
for category_name, keys in info_categories.items():
|
| 127 |
-
|
| 128 |
for key in keys:
|
| 129 |
-
if key in info and info[key] not
|
| 130 |
value = info[key]
|
| 131 |
-
if key in ["exDividendDate","lastSplitDate","governanceEpochDate","compensationAsOfEpochDate"]:
|
| 132 |
value = format_timestamp_to_date(value)
|
| 133 |
-
elif key in ["marketCap","enterpriseValue","fullTimeEmployees","volume","averageVolume",
|
|
|
|
| 134 |
value = format_large_number(value)
|
| 135 |
-
elif isinstance(value,(int,float)):
|
| 136 |
-
if 'percent' in key.lower() or 'ratio' in key.lower() or 'yield' in key.lower() or 'beta' in key.lower() or '
|
| 137 |
value = f"{value:.2%}"
|
| 138 |
elif 'price' in key.lower() or 'dividend' in key.lower() or 'average' in key.lower():
|
| 139 |
value = f"{value:.2f}"
|
| 140 |
else:
|
| 141 |
value = f"{value:,.0f}"
|
| 142 |
-
|
| 143 |
-
|
| 144 |
-
|
| 145 |
-
categorized_html += f"<h2 class='card-category-title'>{category_name}</h2><div class='card'><div class='card-content-grid'>{category_html}</div></div>"
|
| 146 |
|
| 147 |
extra_sections = ""
|
| 148 |
if long_summary:
|
| 149 |
extra_sections += f"<div class='big-box'><h2>Business Summary</h2><p>{long_summary}</p></div>"
|
| 150 |
-
|
| 151 |
if officers:
|
| 152 |
officer_rows = "".join(
|
| 153 |
f"<tr><td>{o.get('name','')}</td><td>{o.get('title','')}</td><td>{o.get('age','')}</td></tr>"
|
|
@@ -159,6 +80,6 @@ def fetch_info(symbol):
|
|
| 159 |
content_html = f"{categorized_html}{extra_sections}"
|
| 160 |
|
| 161 |
except Exception as e:
|
| 162 |
-
content_html = f"<h1>Error</h1><p>{e}</p>"
|
| 163 |
|
| 164 |
-
return f"
|
|
|
|
| 1 |
# info.py
|
| 2 |
import yfinance as yf
|
| 3 |
+
from common import format_large_number, format_timestamp_to_date, wrap_html, STYLE_BLOCK
|
| 4 |
|
| 5 |
def fetch_info(symbol):
|
| 6 |
+
yfsymbol = f"{symbol}.NS"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
try:
|
| 8 |
ticker = yf.Ticker(yfsymbol)
|
| 9 |
info = ticker.info
|
| 10 |
+
if not info:
|
| 11 |
+
content_html = "<h1>No info available</h1>"
|
| 12 |
+
else:
|
| 13 |
long_summary = info.pop("longBusinessSummary", None)
|
| 14 |
officers = info.pop("companyOfficers", None)
|
| 15 |
+
|
| 16 |
+
# Categories
|
| 17 |
info_categories = {
|
| 18 |
"Company Overview": [
|
| 19 |
"longName", "symbol", "exchange", "quoteType", "sector", "industry",
|
|
|
|
| 46 |
|
| 47 |
categorized_html = ""
|
| 48 |
for category_name, keys in info_categories.items():
|
| 49 |
+
category_key_value_html = ""
|
| 50 |
for key in keys:
|
| 51 |
+
if key in info and info[key] is not None and info[key] != []:
|
| 52 |
value = info[key]
|
| 53 |
+
if key in ["exDividendDate", "lastSplitDate", "governanceEpochDate", "compensationAsOfEpochDate"]:
|
| 54 |
value = format_timestamp_to_date(value)
|
| 55 |
+
elif key in ["marketCap", "enterpriseValue", "fullTimeEmployees", "volume", "averageVolume",
|
| 56 |
+
"averageVolume10days", "sharesOutstanding", "impliedSharesOutstanding", "regularMarketVolume"]:
|
| 57 |
value = format_large_number(value)
|
| 58 |
+
elif isinstance(value, (int, float)):
|
| 59 |
+
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():
|
| 60 |
value = f"{value:.2%}"
|
| 61 |
elif 'price' in key.lower() or 'dividend' in key.lower() or 'average' in key.lower():
|
| 62 |
value = f"{value:.2f}"
|
| 63 |
else:
|
| 64 |
value = f"{value:,.0f}"
|
| 65 |
+
category_key_value_html += f"<div class='key-value-pair'><h3>{key.replace('_',' ').title()}</h3><p>{value}</p></div>"
|
| 66 |
+
if category_key_value_html:
|
| 67 |
+
categorized_html += f"<h2>{category_name}</h2><div class='card'><div class='card-content-grid'>{category_key_value_html}</div></div>"
|
|
|
|
| 68 |
|
| 69 |
extra_sections = ""
|
| 70 |
if long_summary:
|
| 71 |
extra_sections += f"<div class='big-box'><h2>Business Summary</h2><p>{long_summary}</p></div>"
|
|
|
|
| 72 |
if officers:
|
| 73 |
officer_rows = "".join(
|
| 74 |
f"<tr><td>{o.get('name','')}</td><td>{o.get('title','')}</td><td>{o.get('age','')}</td></tr>"
|
|
|
|
| 80 |
content_html = f"{categorized_html}{extra_sections}"
|
| 81 |
|
| 82 |
except Exception as e:
|
| 83 |
+
content_html = f"<h1>Error</h1><p>{str(e)}</p>"
|
| 84 |
|
| 85 |
+
return wrap_html(f"Company Info for {symbol}", content_html)
|