implemented /news and deleted debugbot (edit BOT_API_KEY instead) #2
@ -9,7 +9,7 @@ __license__ = "None"
|
|||||||
|
|
||||||
# side-dependencies: none
|
# side-dependencies: none
|
||||||
# Work in Progress
|
# Work in Progress
|
||||||
# Api-Key: 5228016873:AAGFrh0P6brag7oD3gxXjCh5gnLLE8JMvMs
|
# Api-Key: 5228016873:AAGFrh0P6brag7oD3gxXjCh5gnLLE8JMvMs /debugAPI Key: 5108535940:AAF5FpPHNV96WxGCDt8aMrGGKke1VILYib4 (https://t.me/mynewdebugbot)
|
||||||
# text bot at t.me/projektaktienbot
|
# text bot at t.me/projektaktienbot
|
||||||
# API Documentation https://core.telegram.org/bots/api
|
# API Documentation https://core.telegram.org/bots/api
|
||||||
# Code examples https://github.com/eternnoir/pyTelegramBotAPI#getting-started
|
# Code examples https://github.com/eternnoir/pyTelegramBotAPI#getting-started
|
||||||
@ -21,7 +21,12 @@ import time
|
|||||||
import sys
|
import sys
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
|
import news_fetcher
|
||||||
|
|
||||||
from telebot import types
|
from telebot import types
|
||||||
|
from dotenv import load_dotenv
|
||||||
|
|
||||||
|
load_dotenv()
|
||||||
|
|
||||||
bot_version = "0.0.1"
|
bot_version = "0.0.1"
|
||||||
user_list = []
|
user_list = []
|
||||||
@ -32,6 +37,7 @@ class User: # Currently saving users in this class to test functionality -> late
|
|||||||
self.chat_id = int(p_chat_id)
|
self.chat_id = int(p_chat_id)
|
||||||
self.user_name = str(p_user_name)
|
self.user_name = str(p_user_name)
|
||||||
|
|
||||||
|
print(os.getenv('BOT_API_KEY'))
|
||||||
bot = telebot.TeleBot(os.getenv('BOT_API_KEY'))
|
bot = telebot.TeleBot(os.getenv('BOT_API_KEY'))
|
||||||
|
|
||||||
@bot.message_handler(commands=['start']) # /start -> saving as new user and sending welcome
|
@bot.message_handler(commands=['start']) # /start -> saving as new user and sending welcome
|
||||||
@ -45,15 +51,18 @@ def send_start(message):
|
|||||||
user_list.append(new_user)
|
user_list.append(new_user)
|
||||||
|
|
||||||
bot.reply_to(message, "Welcome to this share bot project. Type /help to get information on what this bot can do")
|
bot.reply_to(message, "Welcome to this share bot project. Type /help to get information on what this bot can do")
|
||||||
|
|
||||||
|
|
||||||
@bot.message_handler(commands=['version'])
|
@bot.message_handler(commands=['version'])
|
||||||
def send_version(message):
|
def send_version(message):
|
||||||
bot.reply_to(message, bot_version)
|
bot.reply_to(message, bot_version)
|
||||||
|
|
||||||
|
|
||||||
@bot.message_handler(commands=['help']) # /help -> sending all functions
|
@bot.message_handler(commands=['help']) # /help -> sending all functions
|
||||||
def send_welcome(message):
|
def send_welcome(message):
|
||||||
bot.reply_to(message, "/id or /auth for authentication. /update to get updates on your shares. /users to see all users. For further details see aktienbot.flokaiser.com")
|
bot.reply_to(message, "/id or /auth for authentication. /update to get updates on your shares. /users to see all users. For further details see aktienbot.flokaiser.com")
|
||||||
|
|
||||||
|
|
||||||
@bot.message_handler(commands=['users'])
|
@bot.message_handler(commands=['users'])
|
||||||
def send_all_users(message):
|
def send_all_users(message):
|
||||||
print('Debug: users command')
|
print('Debug: users command')
|
||||||
@ -78,6 +87,15 @@ def send_update(message):
|
|||||||
bot.send_message(chat_id=user_id, text='This is your update')
|
bot.send_message(chat_id=user_id, text='This is your update')
|
||||||
|
|
||||||
|
|
||||||
|
@bot.message_handler(commands=['news']) # /news -> send news by keyword
|
||||||
|
def send_news(message):
|
||||||
|
user_id = int(message.from_user.id)
|
||||||
|
#Get Information for user with this id
|
||||||
|
articles = news_fetcher.get_top_news_by_keyword("bitcoin") #tbd: get keyword from db
|
||||||
|
formatted_article = news_fetcher.format_article(articles["articles"][0])
|
||||||
|
bot.send_message(chat_id=user_id, text=formatted_article)
|
||||||
|
|
||||||
|
|
||||||
@bot.message_handler(func=lambda message: True) # Returning that command is unkown for any other statement
|
@bot.message_handler(func=lambda message: True) # Returning that command is unkown for any other statement
|
||||||
def echo_all(message):
|
def echo_all(message):
|
||||||
answer = 'Do not know this command or text: ' + message.text
|
answer = 'Do not know this command or text: ' + message.text
|
||||||
|
Loading…
Reference in New Issue
Block a user