0

Вот результат, при выводе через print:

[<telebot.types.PhotoSize object at 0x0000026AD9EF5F48>, <telebot.types.PhotoSize object at 0x0000026AD9F13AC8>, <telebot.types.PhotoSize object at 0x0000026AD9F13708>, <telebot.types.PhotoSize object at 0x0000026AD9F13A08>]

А вот необходимый результат, который выводится в Телеграм, а скрипт видит тот, что находится выше (то бишь не этот):

{'file_id': 'AgACAgIAAxkDAAIVtmDkeRZW6BDKvGfHCDdKlm6n-R89AAJ9tjEbnxYoS1OmsWjpYKoPAQADAgADcwADIAQ', 'file_unique_id': 'AQADfbYxG58WKEt4', 'width': 62, 'height': 90, 'file_size': 1551}

def find_file_ids(message):
for file in os.listdir('photo/'):
    if file.split('.')[-1] == 'jpg':
        f = open('photo/'+file, 'rb')
        res = bot.send_photo(message.chat.id, f, None)
        print(res)
    time.sleep(3)

Мне же нужно получить тот результат, который выводится в самом Телеграм, а затем получить file_id фотографии

1 ответ 1

1

file_id находится в объекте PhotoSize. Просто берите последний элемент из массива и получайте id файла:

def find_file_ids(message):
for file in os.listdir('photo/'):
    if file.split('.')[-1] == 'jpg':
        f = open('photo/'+file, 'rb')
        res = bot.send_photo(message.chat.id, f, None)
        file_id = res[-1].file_id
        print(res)
    time.sleep(3)
1
  • 1
    Спасибо огромное, я с эти пол дня мучался 6 июл 2021 в 21:05

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.