Reformatting
This commit is contained in:
@@ -23,23 +23,23 @@ 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()) # retrieve currency from data
|
||||
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()) # stock prices of last few days
|
||||
|
||||
stock_price = recent_data.iloc[-1]["Close"] # retrieve latest stock price
|
||||
|
||||
|
||||
recent_data = pandas.DataFrame(search_result.retrieve_recent_data()) # stock prices of last few days
|
||||
|
||||
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) # return + currency
|
||||
|
||||
|
||||
str_return = str(stock_price) + " " + str(currency) # return + currency
|
||||
|
||||
return str_return
|
||||
|
||||
except RuntimeError: # if no shares are found for germany (e.g. isin: US.....)
|
||||
|
||||
except RuntimeError: # if no shares are found for germany (e.g. isin: US.....)
|
||||
try:
|
||||
my_Converter = CurrencyConverter() # need a currency converter
|
||||
|
||||
my_Converter = CurrencyConverter() # need a currency converter
|
||||
|
||||
search_result = investpy.search_quotes(text=str_search_for, products=['stocks'], n_results=1)
|
||||
|
||||
currency = str(search_result.retrieve_currency())
|
||||
@@ -47,10 +47,10 @@ def get_share_price(str_search_for):
|
||||
recent_data = pandas.DataFrame(search_result.retrieve_recent_data())
|
||||
|
||||
stock_price = recent_data.iloc[-1]["Close"]
|
||||
|
||||
#convert stock price from currency to EUR
|
||||
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)
|
||||
|
||||
str_return = str(stock_price) + " EUR"
|
||||
@@ -109,17 +109,16 @@ def get_share_information(str_search_for):
|
||||
|
||||
|
||||
def get_share_information_markdown(str_search_for):
|
||||
|
||||
try:
|
||||
search_result = investpy.search_quotes(text=str_search_for, products=['stocks'],
|
||||
countries=['germany'], n_results=1)
|
||||
|
||||
countries=['germany'], n_results=1)
|
||||
|
||||
except RuntimeError as e:
|
||||
return hf.make_markdown_proof(f"no shares found for \"{str_search_for}\"") # if no shares are found, make error message markdown proof and return
|
||||
return hf.make_markdown_proof(f"no shares found for \"{str_search_for}\"") # if no shares are found, make error message markdown proof and return
|
||||
|
||||
except ConnectionError as e:
|
||||
return hf.make_markdown_proof(f"connection not possible. Try again later.") # if no connection, make error message markdown proof and return
|
||||
|
||||
return hf.make_markdown_proof(f"connection not possible. Try again later.") # if no connection, make error message markdown proof and return
|
||||
|
||||
str_return = f'*{hf.make_markdown_proof(search_result.name)}*\n_{hf.make_markdown_proof(search_result.symbol)}_\nworth: {hf.make_markdown_proof(get_share_price(str_search_for))}'
|
||||
return str_return
|
||||
|
||||
|
Reference in New Issue
Block a user