diff --git a/telegram_bot/bot.py b/telegram_bot/bot.py index fabe6ec..957da84 100644 --- a/telegram_bot/bot.py +++ b/telegram_bot/bot.py @@ -276,14 +276,12 @@ def send_share_update(message): """ user_id = int(message.from_user.id) - #Get Information for user with this id - bot.send_message(chat_id=user_id, text='Send symbol of share:') - #str_share_price = shares.wait_for_share.main_loop(bot) + bot.send_message(chat_id=user_id, text='Send Symbol/ISIN of share or name of company:') bot.register_next_step_handler(message, send_share_price) def send_share_price(message): - str_share_price = share_fetcher.get_share_price(str(message.text)) - bot.reply_to(message, str_share_price) # add dollar symbol etc. + str_share_price = share_fetcher.get_share_information(str(message.text)) + bot.reply_to(message, str_share_price) @bot.message_handler(commands=['allnews', 'Allnews']) # /allnews -> get all news @@ -297,7 +295,7 @@ def send_all_news(message): :rtype: none """ - + user_id = int(message.from_user.id) keywords = api_handler.get_user_keywords(user_id) # get keywords of user diff --git a/telegram_bot/requirements.txt b/telegram_bot/requirements.txt index fe33bb0..8b22f44 100644 --- a/telegram_bot/requirements.txt +++ b/telegram_bot/requirements.txt @@ -7,3 +7,5 @@ requests~=2.27.1 APScheduler~=3.9.1 croniter~=1.3.4 tzlocal==2.1 +investpy~=1.0.8 +pandas~=1.4.1 \ No newline at end of file diff --git a/telegram_bot/shares/share_fetcher.py b/telegram_bot/shares/share_fetcher.py index c7ec63f..c6a0f2b 100644 --- a/telegram_bot/shares/share_fetcher.py +++ b/telegram_bot/shares/share_fetcher.py @@ -7,20 +7,42 @@ __version__ = "0.0.2" __license__ = "None" import yfinance +import investpy +import pandas -def get_share_price(str_symbol): - - """ get current share price for a certain symbol - :type str_symbol: string - :param str_symbol: share symbol to get price for +def get_share_price(str_search_for): + """_summary_ - :raises: + Args: + str_search_for (_type_): _description_ - :rtype: + Returns: + _type_: _description_ """ - my_share_info = yfinance.Ticker(str_symbol) - my_share_data = my_share_info.info - #my_return_string = f'{my_share_data["regularMarketPrice"]} {my_share_data["currency"]}' - my_return_string = f'{my_share_data["regularMarketPrice"]}' - return my_return_string \ No newline at end of file + search_result = investpy.search_quotes(text=str_search_for, products=['stocks'], + countries=['germany'], 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"] + + str_return =str(stock_price) + " " + str(currency) + + return str_return + +def get_share_information(str_search_for): + search_result = investpy.search_quotes(text=str_search_for, products=['stocks'], + countries=['germany'], n_results=1) + + str_return = "Company: " + search_result.name + "\nSymbol: " + search_result.symbol + "\nCurrent Price/Share: " + get_share_price(str_search_for) + + return str_return + + + +if __name__ == "__main__": + print(get_share_price("AAPL")) + print(get_share_information("AAPL")) \ No newline at end of file