D
D
Dmitry Makarov2021-07-02 19:07:15
Python
Dmitry Makarov, 2021-07-02 19:07:15

How to send a file (photo/gif/video) from a folder in python chronological order?

Hello. I made it so that when you click on the button, the bot sends a random photo to the person. How can I make them send in chronological order, and when they end, they start again?

@bot.message_handler(content_types=['text'])
def event(message):
  if message.chat.type == "private":
    if message.text == "Случайный арт":
      photo = open('Картиночки/' + random.choice(os.listdir('Картиночки')), 'rb')
      bot.send_photo(message.chat.id, photo)

Answer the question

In order to leave comments, you need to log in

2 answer(s)
C
che_aa, 2021-07-02
@che_aa

For each person, it is necessary to save the last sent picture to the database, and check the database with each subsequent sending.

A
Antonio Solo, 2021-07-03
@solotony

to send "in chronological order" use os.stat to get the file's creation time. sort by it. well, save the last photo sent in some database so that next time you can send the next one

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question