Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -3,6 +3,7 @@ import datetime
|
|
3 |
import requests
|
4 |
import pytz
|
5 |
import yaml
|
|
|
6 |
from bs4 import BeautifulSoup
|
7 |
from tools.final_answer import FinalAnswerTool
|
8 |
|
@@ -19,15 +20,13 @@ def get_stock_price(ticker: str) -> str:
|
|
19 |
"""
|
20 |
|
21 |
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
soup = BeautifulSoup(response.text, "html.parser")
|
30 |
-
price_span = soup.find("fin-streamer", {"data-field": "regularMarketPrice"})
|
31 |
|
32 |
if price_span:
|
33 |
return f"The current price of {ticker} is ${price_span.text}"
|
|
|
3 |
import requests
|
4 |
import pytz
|
5 |
import yaml
|
6 |
+
import yfinance as yf
|
7 |
from bs4 import BeautifulSoup
|
8 |
from tools.final_answer import FinalAnswerTool
|
9 |
|
|
|
20 |
"""
|
21 |
|
22 |
|
23 |
+
try:
|
24 |
+
stock = yf.Ticker(ticker)
|
25 |
+
price = stock.info.get("regularMarketPrice", "N/A") # Ensure correct field
|
26 |
+
currency = stock.info.get("currency", "USD") # Get currency
|
27 |
+
return f"{currency} {price:,.2f}" if price != "N/A" else "Price unavailable"
|
28 |
+
except Exception as e:
|
29 |
+
return f"Error fetching price: {e}"
|
|
|
|
|
30 |
|
31 |
if price_span:
|
32 |
return f"The current price of {ticker} is ${price_span.text}"
|