R
R
Rudolf Nemtsev2022-01-31 17:30:31
Python
Rudolf Nemtsev, 2022-01-31 17:30:31

How to randomly open photos in Telegram Bot in Python?

Help with randomizing photos in Python in Telegram bot)

I have a bot project that, when you click on any inline button, should open pictures (depending on the number of photos in the folder).
If a person clicks on the Moscow button, then randomly the bot must select a folder in the Moscow folder (yes, there are folders in the Moscow folder in which photos are stored) and send it to the user, otherwise the folder stores a txt file with text that must be written together

61f7f27081451305272552.jpeg
61f7f27807996969094183.jpeg
61f7f456b0858360620526.jpeg
61f7f4682066a427923839.jpeg
61f7f4748ce8b615944193.jpeg
61f7f47e99ac9077688062.jpeg

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
SKEPTIC, 2022-01-31
@pro100chel

You have folders (Moscow, St. Petersburg, Kazan, etc.) In each of them there are still folders (let's say there is a Kremlin folder in Moscow). This Kremlin folder has txt and pictures.
Let the user press the "Moscow" button. There are 3 folders: the Kremlin, Embankment, Sparrow Hills. Next, we get a list of all subfolders of the Moscow folder and randomly select any. We get its name, go into it and get all the photos (you can name 1.jpg, 2.jpg, etc., or get a list of all files with certain extensions jpg, png, etc.), it is advisable to always name the txt file the same (let's say desc.txt).
And we send the whole thing to the user.
Scary task "How to randomly open photos in Telegram Bot in Python?" results in several small subtasks,

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question