Python
- 16 ответов
- 0 вопросов
8
Вклад в тег
async def main():
tasks = []
for _ in range(10):
task = asyncio.create_task(waste_time()) # создаем задачу
tasks.append(task)
await task # ожидаем выполнения
# итерация завершена, переходим к следующей
import asyncio
from time import time, sleep
async def waste_time():
print("Start work...")
await asyncio.sleep(2)
print("End work!")
async def main():
tasks = []
for _ in range(10):
task = asyncio.create_task(waste_time())
tasks.append(task)
await asyncio.gather(*tasks)
asyncio.run(main())
client.send_message('me', '<a href="tg://user?id=me">Mentions</a>', parse_mode="html")
import telebot, requests, bs4
from bs4 import BeautifulSoup
bot = telebot.TeleBot("TOKEN")
def pars():
page_link = 'https://random.cat/'
response = requests.get(page_link)
html = response.content
soup = BeautifulSoup(html, 'html.parser')
obj = soup.find('img', attrs={'id': 'cat'})
return obj.attrs['src']
@bot.message_handler(commands=['rcat'])
def randomcat(message):
bot.send_message(message.chat.id, pars())
bot.polling(none_stop=True)