added keywords from db (not working currently)
This commit is contained in:
parent
26a6561682
commit
c489e9ab46
@ -34,7 +34,7 @@ class API_Handler:
|
||||
self.token = None
|
||||
|
||||
def reauthorize(self, email, password):
|
||||
"""reauthorizes the user
|
||||
"""set new credentials
|
||||
|
||||
Args:
|
||||
email (string): email of the user
|
||||
@ -207,7 +207,7 @@ if __name__ == "__main__":
|
||||
|
||||
print("This is a module for the telegram bot. It is not intended to be run directly.")
|
||||
handler = API_Handler("https://aktienbot.flokaiser.com/api", "bot@example.com", "bot")
|
||||
|
||||
keywords = handler.get_user_keywords(user_id = 1709356058) #user_id is mine (Linus)
|
||||
print(handler.token)
|
||||
keywords = handler.get_user_keywords(user_id = 1709356058) #user_id is currently mine (Linus)
|
||||
print(keywords)
|
||||
sys.exit(1)
|
@ -28,12 +28,17 @@ import shares.share_fetcher as share_fetcher
|
||||
from telebot import types
|
||||
from dotenv import load_dotenv
|
||||
|
||||
from api_handler import API_Handler
|
||||
|
||||
|
||||
load_dotenv()
|
||||
|
||||
bot_version = "0.2.1"
|
||||
user_list = []
|
||||
|
||||
#create api handler
|
||||
api_handler = API_Handler("https://aktienbot.flokaiser.com", os.getenv("BOT_EMAIL"), os.getenv("BOT_PASSWORD"))
|
||||
|
||||
class User: # Currently saving users in this class to test functionality -> later database
|
||||
def __init__(self, p_user_id, p_user_name, p_chat_id):
|
||||
|
||||
@ -222,11 +227,11 @@ def send_news(message):
|
||||
:rtype: none
|
||||
"""
|
||||
|
||||
keyword = "bitcoin"
|
||||
user_id = int(message.from_user.id)
|
||||
#Get Information for user with this id
|
||||
keywords = api_handler.get_keywords(user_id)
|
||||
keyword = keywords[0]
|
||||
|
||||
articles = news.get_top_news_by_keyword(keyword) #tbd: get keyword from db
|
||||
articles = news.get_top_news_by_keyword(keywords[0])
|
||||
try:
|
||||
formatted_article = news.format_article(articles["articles"][0])
|
||||
except IndexError:
|
||||
@ -235,6 +240,27 @@ def send_news(message):
|
||||
bot.send_message(chat_id=user_id, text=f"_keyword: {keyword}_\n\n" + formatted_article, parse_mode="MARKDOWN")
|
||||
|
||||
|
||||
@bot.message_handler(commands=['addkeyword'])
|
||||
def add_keyword(message):
|
||||
""" Add keyword to user
|
||||
:type message: message object bot
|
||||
:param message: message that was reacted to, in this case always '/addkeyword'
|
||||
|
||||
:raises: none
|
||||
|
||||
:rtype: none
|
||||
"""
|
||||
user_id = int(message.from_user.id)
|
||||
bot.send_message(chat_id=user_id, text='Type keyword to add:')
|
||||
bot.register_next_step_handler(message, store_keyword)
|
||||
|
||||
def store_keyword(message):
|
||||
user_id = int(message.from_user.id)
|
||||
keyword = str(message.text)
|
||||
api_handler.add_keyword(user_id, keyword)
|
||||
bot.send_message(chat_id=user_id, text=f'Keyword {keyword} added.')
|
||||
|
||||
|
||||
@bot.message_handler(func=lambda message: True) # Returning that command is unkown for any other statement
|
||||
def echo_all(message):
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user