M
M
Maxim Rybka2021-03-21 20:28:38
Python
Maxim Rybka, 2021-03-21 20:28:38

How to pass a function as an argument to bot.send_photo?

I am writing a bot in python. There is a function that gets pictures by class:

def getImages(limit): # картинки
    return soup.find_all('img', class_='market_listing_item_img', limit=limit)

And also there is a command that displays a picture (at the specified url) and text:
@dp.message_handler(commands=['see_products'])
async def process_seeproducts_command(message: types.Message):
    limit = 3 
    i = 0
    while i <= limit:
        prices = parser_from_tp.getPrices(limit)
        titles = parser_from_tp.getTitles(limit)
        quantities = parser_from_tp.getQuantities(limit)
        await bot.send_photo(chat_id, url, caption='Товар: '+titles[i].text+'\nЦена: '+prices[i].text+'\nКол-во: '+quantities[i].text)
        i = i+1

I need to pass a function to bot.send_photo as an argument, not a url, how can I do this?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
soremix, 2021-03-21
@Uchiha_Obito

Firstly, then the function needs to be improved, because it returns bs4 objects, not
urls. Secondly, sendPhoto sends one image. So either return just one url or use sendMediaGroup

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question