from pytube import YouTube
yt = YouTube("https://youtu.be/uCNWuSbPnt4")
resolutions = sorted(
set(stream.resolution for stream in yt.streams.filter(type='video')),
key=lambda s: int(s.split('p')[0])
)
print(*resolutions, sep='\n')
144p
240p
360p
480p
720p
1080p
1440p
2160p
fetchone()
возвращает один результат в виде кортежа полей, в вашем случае состоящего из одного элемента — значения поля time
:last_command_use_time = cursor.fetchone()
last_command_use_time
:last_command_use_time = cursor.fetchone()[0]
queue.Queue
), Redis или SQLite. \s
в регулярных выражениях:import re
print(all(re.fullmatch(r'\s', string) for string in ('\n', '\r', '\t', ' '))) # True
pacman -Sy <имя пакета>
a, b, c, d = 'abcd'
lst = [1, a, b, c, d, 2, a, b, c, d, 3, a, b, c, d]
result = {lst[i]: {lst[i+1]: lst[i+2], lst[i+3]: lst[i+4]} for i in range(0, len(lst), 5)}
print(result) # {1: {'a': 'b', 'c': 'd'}, 2: {'a': 'b', 'c': 'd'}, 3: {'a': 'b', 'c': 'd'}}
result = {}
for i in range(0, len(lst), 5):
result[lst[i]] = {lst[i+1]: lst[i+2], lst[i+3]: lst[i+4]}
print(result) # {1: {'a': 'b', 'c': 'd'}, 2: {'a': 'b', 'c': 'd'}, 3: {'a': 'b', 'c': 'd'}}
import datetime as dt
joined = … # Момент, с которого пользователь начал пользоваться ботом (тип данных dt.datetime, из БД)
now = dt.datetime.now()
days_with_us = (now - joined).days
msg = f"Вы с нами дней: {days}"
datetime.timedelta
в удобочитаемое представление. Например, Humanize: https://python-humanize.readthedocs.io/en/latest/ --user-data-dir
.ConnectionError
:from requests.exceptions import ConnectionError
...
except (telebot.apihelper.ApiException, RequestException) as e:
...
import telebot
API_TOKEN = '<api_token>'
bot = telebot.TeleBot(API_TOKEN)
@bot.message_handler(content_types=['photo'])
def detect_photo(message: telebot.types.Message):
bot.reply_to(message, "Обнаружена картинка.")
bot.infinity_polling()
def is_photo_document(message: telebot.types.Message) -> bool:
mime_type = message.document.mime_type
return mime_type in ('image/jpeg', 'image/png', 'image/webp')
@bot.message_handler(func=is_photo_document, content_types=['document'])
def detect_photo_as_document(message: telebot.types.Message):
bot.reply_to(message, "Обнаружена картинка, отправленная документом.")
unread_count
каждого диалога, узнать, есть ли непрочитанные сообщения: https://docs.telethon.dev/en/stable/modules/custom...