W
W
whorsash2018-05-29 10:27:19
Python
whorsash, 2018-05-29 10:27:19

What is the best way and how to do it?

Hello! I am writing a telegram bot and thus learning the Python language.
I'm interested in the question.
What is the best way to organize the loading of information in the form of a description, files: several photos, a document of the docx, pdf extension using a database or writing directly in the code?
The bot looks like this: a person enters a certain number, for example 123, under this number you need to display a description, files (several photos, and documents: 1 docx, 1 pdf). The bot gave out information and offers a search for other numbers, and the process is repeated. If a person entered a number incorrectly, the bot writes the message "Oops... there is no such command... please re-enter".
How can this be organized: using conditions or a loop?
There are so many numbers...
It is necessary to make sure that the user receives specific data and files from the bot.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Vitaly Stolyarov, 2018-05-29
@Ni55aN

Graph. states.
https://refactoring.guru/ru/design-patterns/state

A
Andrey, 2018-05-29
@poslannikD

What is the best way to organize the loading of information in the form of a description, files: several photos, a document of the docx, pdf extension using a database or writing directly in the code?

Several options:
First: create a configuration file
type
zifrZifrAiLyLy=123
{
//document and foto list
doc 123
foto 123_1
foto123_2
и тд
}
When loading the bot, parse this configuration file. The config can be in json, txt (separated), xml or any other convenient format. The choice of a specific storage format depends on the amount of data in their structure, and so on.
If the filling of the file does not depend on the programmer, but on other persons, the option is ideal. On one project it was necessary to do something similar. The person filled out the table in Excel and saved it as txt (the delimiter of m / y cells is a tab character). I parsed the file in the program, after writing and debugging the code, you don’t need to return to the project :) And if it’s hardcoded, then you have to edit the code for every sneeze, which is not good.
Option two: through the database. - Well, if there are millions of lines of data or those who fill in the database do it through some kind of web interface. Otherwise, the option is honestly weak.
How can this be organized: using conditions or a loop?
- main loop processing user input + conditions

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question