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')

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(, sti)
 bot.send_message( send_mess, sti, reply_markup=markup)

class Currency_EUR:
 EUR_LINK = ''
 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))

 def EUR(message):
 get_message_bot = message.text.strip().lower()
 if get_message_bot == 'Euro':
 bot.send_message(, 'the current exchange rate: 1 Euro =' + str(currency_EUR) + 'RUB')

# The main class
class Currency_USD:
 # Link to the correct page
 # 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))

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

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

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

# Create object and call the bot
April 19th 20 at 12:31
0 answer

Find more questions by tags Telegram