Skip to content

Commit

Permalink
added current stock price (TheAlgorithms#1590)
Browse files Browse the repository at this point in the history
* added current stock price

* Ten lines or less
  • Loading branch information
vansh1999 authored and cclauss committed Nov 23, 2019
1 parent e09bf69 commit 4c75f86
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions web_programming/current_stock_price.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import requests
from bs4 import BeautifulSoup


def stock_price(symbol: str = "AAPL") -> str:
url = f"https://in.finance.yahoo.com/quote/{symbol}?s={symbol}"
soup = BeautifulSoup(requests.get(url).text, "html.parser")
class_ = "My(6px) Pos(r) smartphone_Mt(6px)"
return soup.find("div", class_=class_).find("span").text


if __name__ == "__main__":
for symbol in "AAPL AMZN IBM GOOG MSFT ORCL".split():
print(f"Current {symbol:<4} stock price is {stock_price(symbol):>8}")

0 comments on commit 4c75f86

Please sign in to comment.