Answer the question
In order to leave comments, you need to log in
Telegram bot information output?
Good day! I am writing a telegram bot in python for automatic sales, using the aiogram library. When you press the / start command, the bot sends a list of cities, in this format
Cities: City1
City2
Etc.
@dp.message_handler(state=Form.choose_district)
async def process_name(message: types.Message, state: FSMContext):
"""
Process user name
"""
async with state.proxy() as data:
data['choose_district'] = message.text
try:
f = open('product.txt', 'w')
g = open('product.txt', 'r')
for element in db.check_product(data['choose_district']):
f.writelines(element)
f.write('\n')
f.close()
for line in g.readlines():
s = re.split(r'I', line)
await bot.send_message(message.from_user.id, "Товары - цена:\n"
"{0} - {1} \n".format(s[0], s[1], bot.get_me()),
reply_markup=inline_kb1)
except:
await bot.send_message(message.from_user.id, "Такого района не существует")
await state.finish()
Answer the question
In order to leave comments, you need to log in
Somewhere there should be a database, and in it a table with the names of cities. It is necessary to add a column with city numbers (unique) to this table, or create a new city-to-number correspondence table, and use this column of numbers to find the city by number, and then pass the city itself to the db.check_product (city) query, if I'm correct understood the meaning of this code.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question