Answer the question
In order to leave comments, you need to log in
How to merge two bots into one?
How to merge two bots into one?
One parses news from a specific site, and the other parses the banking exchange.
Can't connect and get them to work together.
Please help, just tell me what to do and how to do it.
import telebot
import requests
from bs4 import BeautifulSoup as BS
from telebot import types
bot = telebot.TeleBot(config.token)
@bot.message_handler(commands=['start', 'help'])
def main(message):
markup = types.ReplyKeyboardMarkup(resize_keyboard=True, row_width=2)
itembtn1 = types.KeyboardButton('News')
itembtn2 = types.KeyboardButton('Forex')
markup.add(itembtn1, itembtn2)
msg = bot.send_message(message.chat.id, "Select one:", reply_markup=markup)
bot.register_next_step_handler(msg, process_switch_step)
def process_switch_step(message):
if (message.text == 'Forex'):
news(message)
main(message)
elif (message.text == 'News'):
forex(message)
def news(message):
url = 'https://news.am/arm/'
page = requests.get(url)
new_news = []
soup = BS(page.text, "html.parser")
news = soup.findAll('a', class_='news-item')
for i in range(len(news)):
if news[i].find('span', class_='title') is not None:
new_news.append(f"{news[i]['href']} \n {news[i].text}")
for i in range(len(new_news)):
@bot.message_handler(content_types=['text'])
def send_text(message):
if message.text == 'News':
bot.send_message(message.chat.id, (''.join(new_news[:10])))
def forex(message):
url = 'https://b24.am/other/'
page = requests.get(url)
new_news = []
soup = BS(page.text, "html.parser")
news = soup.findAll('div', class_='runfor')
for i in range(len(news)):
if news[i].find('span', class_='R') is not None:
new_news.append(news[i].text)
for i in range(len(new_news)):
@bot.message_handler(content_types=['text'])
def send_text(message):
if message.text == 'Forex':
bot.send_message(message.chat.id, (''.join(new_news)))
if __name__ == '__main__':
bot.polling(none_stop=True)
Answer the question
In order to leave comments, you need to log in
Make 3 bots in 1. Then delete one.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question