from multiprocessing import Process
class BotProcess:
def __init__(self):
self.process = None
def get(self) -> Process:
return self.process
def is_alive(self) -> bool:
if self.process is not None and self.process.is_alive():
return True
else:
return False
def stop(self) -> None:
self.process.terminate()
self.process = None
def start(self, process: Process) -> None:
self.process = process
self.process.start()
bot_process = BotProcess()
@app.route("/bot-start", methods=["GET"])
def bot_start():
if not bot_process.is_alive():
bot_process.start(Process(target=start_bot))
return "Bot started"
else:
return "Bot is already running"
@app.route("/bot-restart", methods=["GET"])
def bot_restart():
if bot_process.is_alive():
bot_process.stop()
bot_process.start(Process(target=start_bot))
return "Bot restarted"
else:
return "Bot is not running"
@app.route("/bot-stop", methods=["GET"])
def bot_stop():
if bot_process.is_alive():
bot_process.stop()
return "Bot stopped"
else:
return "Bot is not running"
if message.content == "привет":
my_list = ["привет", "ку", "дарова"]
if message.content in my_list:
import telebot
import requests
from bs4 import BeautifulSoup
bot = telebot.TeleBot('тут токен бота')
@bot.message_handler(commands=['gold'])
def echo_all(message):
url = 'https://ru.investing.com/commodities/gold'
response = requests.get(url)
soup = BeautifulSoup(response.text, 'lxml')
gold = soup.find('span', class_='instrument-price_last__KQzyA')
print(gold.text)
bot.send_message(message.chat.id, gold.text + '$')
bot.infinity_polling()
link_string = "https://vk.com/id663629411"
user = link_string.split("/")[-1].replace("id", "")
id
, так что добавьте дополнительную проверку.user
из кода выше в параметр user_ids
def get_user(pattern: str) -> int:
if "[id" in pattern:
return int(pattern.split("|")[0].replace("[id", ""))
if "vk.com/" in pattern:
domen = pattern.split("/")[-1]
return vk.users.get(user_ids=domen)
audio = status["text"]
artist = status["audio"]["artist"]
title = status["audio"]["title"]
appeal = '*id' + str(user_id) + '(' + full_name + ')'
return appeal
if members[i]['first_name'] == user_name_search:
return members[i]['id']
for i in range(len(members)):
if members[i]['first_name'] == user_name_search:
user_id = members[i]['id']
for i in members:
if i['first_name'] == user_name_search:
user_id = i['id']