added comments

This commit is contained in:
Florian Kellermann
2022-05-11 09:40:08 +02:00
parent 653e049f2e
commit f87f8cbf4c
2 changed files with 20 additions and 19 deletions

View File

@@ -22,21 +22,22 @@ def get_share_price(str_search_for):
try:
search_result = investpy.search_quotes(text=str_search_for, products=['stocks'], n_results=1, countries=['germany'])
currency = str(search_result.retrieve_currency())
currency = str(search_result.retrieve_currency()) # retrieve currency from data
# should always be Euro because of countries=['germany']
recent_data = pandas.DataFrame(search_result.retrieve_recent_data())
recent_data = pandas.DataFrame(search_result.retrieve_recent_data()) # stock prices of last few days
stock_price = recent_data.iloc[-1]["Close"]
stock_price = recent_data.iloc[-1]["Close"] # retrieve latest stock price
stock_price = round(float(stock_price), 2)
str_return =str(stock_price) + " " + str(currency)
str_return =str(stock_price) + " " + str(currency) # return + currency
return str_return
except RuntimeError:
except RuntimeError: # if no shares are found for germany (e.g. isin: US.....)
try:
my_Converter = CurrencyConverter()
my_Converter = CurrencyConverter() # need a currency converter
search_result = investpy.search_quotes(text=str_search_for, products=['stocks'], n_results=1)
@@ -46,7 +47,8 @@ def get_share_price(str_search_for):
stock_price = recent_data.iloc[-1]["Close"]
stock_price = my_Converter.convert(float(stock_price), str(currency), 'EUR')
#convert stock price from currency to EUR
stock_price = my_Converter.convert(float(stock_price), str(currency), 'EUR')
stock_price = round(float(stock_price), 2)