Skip to content

Commit cfcc84e

Browse files
MaximSmolskiypre-commit-ci[bot]cclauss
authored
* Empty commit * Fix * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Fix * Apply suggestions from code review --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Christian Clauss <[email protected]>
1 parent 787aa5d commit cfcc84e

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

web_programming/current_stock_price.py

+4-6
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
def stock_price(symbol: str = "AAPL") -> str:
1616
"""
1717
>>> stock_price("EEEE")
18-
'-'
18+
'- '
1919
>>> isinstance(float(stock_price("GOOG")),float)
2020
True
2121
"""
@@ -24,12 +24,10 @@ def stock_price(symbol: str = "AAPL") -> str:
2424
url, headers={"USER-AGENT": "Mozilla/5.0"}, timeout=10
2525
).text
2626
soup = BeautifulSoup(yahoo_finance_source, "html.parser")
27-
specific_fin_streamer_tag = soup.find("fin-streamer", {"data-testid": "qsp-price"})
2827

29-
if specific_fin_streamer_tag:
30-
text = specific_fin_streamer_tag.get_text()
31-
return text
32-
return "No <fin-streamer> tag with the specified data-test attribute found."
28+
if specific_fin_streamer_tag := soup.find("span", {"data-testid": "qsp-price"}):
29+
return specific_fin_streamer_tag.get_text()
30+
return "No <fin-streamer> tag with the specified data-testid attribute found."
3331

3432

3533
# Search for the symbol at https://finance.yahoo.com/lookup

0 commit comments

Comments
 (0)