How to execute 2 functions in python using telegram. bot?

Hi all. I made a parser for the bot in the cart which parses currency with Google. Question: How can I make it to run 2 functions in parallel? That is the function of: currency_USD = Currency_USD() and currency_EUR.check_currency_EUR(). Because if the first is a function of the dollar is parsed only a dollar in the cart and Vice versa. If I send a request to the Euro, it is parsed only the Euro and the dollar do not see, though in the terminal when using print print both request.

import requests
from bs4 import BeautifulSoup
import telebot
from telebot import types
from threading import Thread
from multiprocessing import Process
bot = telebot.TeleBot('1156880733:AAGNUiAiw79mbTVLoD4tOZtykU5JLTORgoi')


@bot.message_handler(commands=['start'])
def start(message):
 markup = types.ReplyKeyboardMarkup(resize_keyboard=True, row_width=1)
 btn1 = types.Keyboardbutton To('Dollar $')
 btn2 = types.Keyboardbutton To('GBP £')
 btn3 = types.Keyboardbutton To('€ €')
 markup.add(btn1, btn2, btn3)
 send_mess = 'Use the keyboard'
 sti = open('stic/fr.webp', 'rb')
 bot.send_sticker(message.chat.id, sti)
 bot.send_message(message.chat.id send_mess, sti, reply_markup=markup)

class Currency_EUR:
 EUR_LINK = 'https://www.google.com/search?client=firefox-b-d&q=%D0%B5%D0%B2%D1%80%D0%BE+%D0%BA+%D1%80%D1%83%D0%B1%D0%BB%D1%8E'
 headers = {'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:75.0) Gecko/20100101 Firefox/75.0'}

 def get_currency_price_EUR(self):
 full_page = requests.get(self.EUR_LINK, headers=self.headers)
 soup = BeautifulSoup(full_page.content, 'html.parser')
 convert = soup.findAll("span", {"class": "DFlfde", "class": "SwHCTb", "data precision": 2})
 return convert[0].text


 def check_currency_EUR(self):
 print('Running parsing Euro...')
 currency_EUR = str(self.get_currency_price_EUR())
 print("current exchange rate: 1 Euro =" + str(currency_EUR))

@bot.message_handler(content_types=['text'])
 def EUR(message):
 get_message_bot = message.text.strip().lower()
 if get_message_bot == 'Euro':
 bot.send_message(message.chat.id, 'the current exchange rate: 1 Euro =' + str(currency_EUR) + 'RUB')

# The main class
class Currency_USD:
 # Link to the correct page
 DOLLAR_RUB = 'https://www.google.com/search?client=firefox-b-d&q=%D0%B4%D0%BE%D0%BB%D0%BB%D0%B0%D1%80+%D0%BA+%D1%80%D1%83%D0%B1%D0%BB%D1%8E'
 # Headers for transmission along with the URL
 headers = {'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.149 Safari/537.36'}

 # Method to get the currency rate
 def get_currency_price_USD(self):
 # Parsim whole page
 full_page = requests.get(self.DOLLAR_RUB, headers=self.headers)
 # Parse using BeautifulSoup
 soup = BeautifulSoup(full_page.content, 'html.parser')
 # Get the value and return it
 convert = soup.findAll("span", {"class": "DFlfde", "class": "SwHCTb", "data precision": 2})
 return convert[0].text

 # Check currency
 def check_currency_USD(self):
 print('Running parsing of the dollar...')
 currency_USD = str(self.get_currency_price_USD())
 print("current exchange rate: 1 dollar =" + str(currency_USD))

@bot.message_handler(content_types=['text'])
 def USD(message):
 get_message_bot = message.text.strip().lower()
 if get_message_bot == 'USD':
 bot.send_message(message.chat.id, "Now the exchange rate is: 1 dollar =" + str(currency_USD) + "RUB")


# Create object and call a method of a dollar
currency_USD = Currency_USD()
currency_USD.check_currency_USD()


#The object creation and method invocation euros
currency_EUR = Currency_EUR()
currency_EUR.check_currency_EUR()

# Create object and call the bot
bot.polling(none_stop=True)
April 19th 20 at 12:31
0 answer

Find more questions by tags Telegram