Working for all isins and new requirements #144
@ -8,3 +8,4 @@ croniter~=1.3.4
|
|||||||
tzlocal==2.1
|
tzlocal==2.1
|
||||||
investpy~=1.0.8
|
investpy~=1.0.8
|
||||||
pandas~=1.4.1
|
pandas~=1.4.1
|
||||||
|
currencyconverter~=0.16.12
|
@ -8,6 +8,7 @@ __license__ = "None"
|
|||||||
|
|
||||||
import investpy
|
import investpy
|
||||||
import pandas
|
import pandas
|
||||||
|
from currency_converter import CurrencyConverter
|
||||||
|
|
||||||
def get_share_price(str_search_for):
|
def get_share_price(str_search_for):
|
||||||
"""get stock price per share for company name or isin or symbol
|
"""get stock price per share for company name or isin or symbol
|
||||||
@ -17,8 +18,8 @@ def get_share_price(str_search_for):
|
|||||||
|
|
||||||
Returns: none
|
Returns: none
|
||||||
"""
|
"""
|
||||||
|
try:
|
||||||
search_result = investpy.search_quotes(text=str_search_for, products=['stocks'], n_results=1, countries=['germany', 'united states'])
|
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())
|
||||||
|
|
||||||
@ -26,10 +27,34 @@ def get_share_price(str_search_for):
|
|||||||
|
|
||||||
stock_price = recent_data.iloc[-1]["Close"]
|
stock_price = recent_data.iloc[-1]["Close"]
|
||||||
|
|
||||||
|
stock_price = round(float(stock_price), 2)
|
||||||
|
|
||||||
str_return =str(stock_price) + " " + str(currency)
|
str_return =str(stock_price) + " " + str(currency)
|
||||||
|
|
||||||
return str_return
|
return str_return
|
||||||
|
|
||||||
|
except RuntimeError:
|
||||||
|
try:
|
||||||
|
my_Converter = CurrencyConverter()
|
||||||
|
|
||||||
|
search_result = investpy.search_quotes(text=str_search_for, products=['stocks'], n_results=1)
|
||||||
|
|
||||||
|
currency = str(search_result.retrieve_currency())
|
||||||
|
|
||||||
|
recent_data = pandas.DataFrame(search_result.retrieve_recent_data())
|
||||||
|
|
||||||
|
stock_price = recent_data.iloc[-1]["Close"]
|
||||||
|
|
||||||
|
stock_price = my_Converter.convert(float(stock_price), str(currency), 'EUR')
|
||||||
|
|
||||||
|
stock_price = round(float(stock_price), 2)
|
||||||
|
|
||||||
|
str_return =str(stock_price) + " EUR"
|
||||||
|
|
||||||
|
return str_return
|
||||||
|
|
||||||
|
except RuntimeError:
|
||||||
|
return "None"
|
||||||
|
|
||||||
def get_share_price_no_currency(str_search_for):
|
def get_share_price_no_currency(str_search_for):
|
||||||
"""get stock price per share for company name or isin or symbol no currency
|
"""get stock price per share for company name or isin or symbol no currency
|
||||||
@ -39,21 +64,49 @@ def get_share_price_no_currency(str_search_for):
|
|||||||
|
|
||||||
Returns: none
|
Returns: none
|
||||||
"""
|
"""
|
||||||
|
try:
|
||||||
search_result = investpy.search_quotes(text=str_search_for, products=['stocks'],
|
search_result = investpy.search_quotes(text=str_search_for, products=['stocks'],
|
||||||
countries=['germany', 'united states'], n_results=1)
|
countries=['germany'], n_results=1)
|
||||||
|
|
||||||
|
|
||||||
recent_data = pandas.DataFrame(search_result.retrieve_recent_data())
|
recent_data = pandas.DataFrame(search_result.retrieve_recent_data())
|
||||||
|
|
||||||
stock_price = recent_data.iloc[-1]["Close"]
|
stock_price = recent_data.iloc[-1]["Close"]
|
||||||
|
|
||||||
|
stock_price = round(float(stock_price), 2)
|
||||||
|
|
||||||
return stock_price
|
return stock_price
|
||||||
|
|
||||||
|
except RuntimeError:
|
||||||
|
my_Converter = CurrencyConverter()
|
||||||
|
|
||||||
|
search_result = investpy.search_quotes(text=str_search_for, products=['stocks'], n_results=1)
|
||||||
|
|
||||||
|
currency = str(search_result.retrieve_currency())
|
||||||
|
|
||||||
|
recent_data = pandas.DataFrame(search_result.retrieve_recent_data())
|
||||||
|
|
||||||
|
stock_price = recent_data.iloc[-1]["Close"]
|
||||||
|
|
||||||
|
stock_price = my_Converter.convert(float(stock_price), str(currency), 'EUR')
|
||||||
|
|
||||||
|
stock_price = round(float(stock_price), 2)
|
||||||
|
|
||||||
|
str_return =str(stock_price)
|
||||||
|
|
||||||
|
return str_return
|
||||||
|
|
||||||
|
|
||||||
def get_share_information(str_search_for):
|
def get_share_information(str_search_for):
|
||||||
search_result = investpy.search_quotes(text=str_search_for, products=['stocks'],
|
search_result = investpy.search_quotes(text=str_search_for, products=['stocks'],
|
||||||
countries=['germany', 'united states'], n_results=1)
|
countries=['germany'], n_results=1)
|
||||||
|
|
||||||
str_return = "Company: " + search_result.name + "\nSymbol: " + search_result.symbol + "\nCurrent Price/Share: " + get_share_price(str_search_for)
|
str_return = "Company: " + search_result.name + "\nSymbol: " + search_result.symbol + "\nCurrent Price/Share: " + get_share_price(str_search_for)
|
||||||
|
|
||||||
return str_return
|
return str_return
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
print(get_share_price("US2515661054"))
|
||||||
|
print(get_share_price("DE0005557508"))
|
||||||
|
print(get_share_price_no_currency("US2515661054"))
|
||||||
|
print(get_share_price_no_currency("DE0005557508"))
|
Loading…
Reference in New Issue
Block a user