Update app.py
Browse files
app.py
CHANGED
|
@@ -11,6 +11,22 @@ import smtplib
|
|
| 11 |
from email.mime.text import MIMEText
|
| 12 |
from email.mime.multipart import MIMEMultipart
|
| 13 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
# ==============================
|
| 15 |
# 📌 LẤY DỮ LIỆU TỪ YFINANCE
|
| 16 |
# ==============================
|
|
@@ -134,7 +150,8 @@ def get_futures_data_from_yahoo_scraping():
|
|
| 134 |
"E-mini Dow ($5) (YM)": "https://finance.yahoo.com/quote/YM=F/"
|
| 135 |
}
|
| 136 |
headers = {
|
| 137 |
-
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36"
|
|
|
|
| 138 |
}
|
| 139 |
futures_data = {}
|
| 140 |
|
|
@@ -162,7 +179,7 @@ def get_futures_data_from_yahoo_scraping():
|
|
| 162 |
|
| 163 |
# Tìm khối lượng
|
| 164 |
volume_elem = soup.find("fin-streamer", {"data-field": "regularMarketVolume"})
|
| 165 |
-
volume =
|
| 166 |
|
| 167 |
if price is not None and change is not None and percent_change is not None:
|
| 168 |
futures_data[name] = {
|
|
|
|
| 11 |
from email.mime.text import MIMEText
|
| 12 |
from email.mime.multipart import MIMEMultipart
|
| 13 |
|
| 14 |
+
# Helper function to parse volume strings like '197.6k' or '1.2M'
|
| 15 |
+
def parse_volume(volume_str):
|
| 16 |
+
try:
|
| 17 |
+
volume_str = volume_str.replace(",", "").strip()
|
| 18 |
+
if volume_str.endswith('k'):
|
| 19 |
+
return float(volume_str[:-1]) * 1000
|
| 20 |
+
elif volume_str.endswith('M'):
|
| 21 |
+
return float(volume_str[:-1]) * 1000000
|
| 22 |
+
elif volume_str.endswith('B'):
|
| 23 |
+
return float(volume_str[:-1]) * 1000000000
|
| 24 |
+
else:
|
| 25 |
+
return float(volume_str)
|
| 26 |
+
except Exception as e:
|
| 27 |
+
st.warning(f"Không thể phân tích khối lượng: {volume_str}. Lỗi: {e}")
|
| 28 |
+
return 0
|
| 29 |
+
|
| 30 |
# ==============================
|
| 31 |
# 📌 LẤY DỮ LIỆU TỪ YFINANCE
|
| 32 |
# ==============================
|
|
|
|
| 150 |
"E-mini Dow ($5) (YM)": "https://finance.yahoo.com/quote/YM=F/"
|
| 151 |
}
|
| 152 |
headers = {
|
| 153 |
+
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36",
|
| 154 |
+
"Accept-Language": "en-US,en;q=0.9"
|
| 155 |
}
|
| 156 |
futures_data = {}
|
| 157 |
|
|
|
|
| 179 |
|
| 180 |
# Tìm khối lượng
|
| 181 |
volume_elem = soup.find("fin-streamer", {"data-field": "regularMarketVolume"})
|
| 182 |
+
volume = parse_volume(volume_elem.text) if volume_elem else 0
|
| 183 |
|
| 184 |
if price is not None and change is not None and percent_change is not None:
|
| 185 |
futures_data[name] = {
|