Python
26
Вклад в тег
answer
не принимает параметр chat_idawait mybot.bot.send_message(chat_id = 123, text=message.text)
await mybot.bot.send_message(627976213, message.text)
from aiogram.contrib.fsm_storage.memory import MemoryStorage
storage = MemoryStorage()
from aiogram.dispatcher import FSMContext
@dp.message_handler(commands=['start'])
async def start(message: types.Message, state=FSMContext):
await message.answer('Вы ввели команду /start, введите команду /stop или /cancel чтобы выйти из меню')
await state.set_state(YourState.name_state)
@dp.message_handler(commands=['stop'], state=YourState.name_state)
async def stop(message: types.Message, state=FSMContext):
await message.answer('Вы ввели команду /stop')
await state.finish()
@dp.message_handler(commands=['cancel'], state='*')
async def cancel(message: types.Message, state=FSMContext):
current_state = await state.get_state()
if current_state is None:
return
await state.finish()
await message.answer('Вы ввели команду /cancel')
d_list
на 100.000 у меня выполнилось за 0.6868....res = []
for dictionary in d_list: # * 100_000:
result_dict = {}
for key in dictionary:
if dictionary[key] is not None:
result_dict[key] = dictionary[key]
result_dict = {**result_dict, **{'qty1': False, 'fp1': False,
'qty2': False, 'fp2': False,
'qty3': False, 'fp3': False}}
if isinstance(dictionary['b'], list):
for z in range(1, len(dictionary['b']) - 1):
result_dict[f'qty{z}'] = dictionary['b'][z - 1]['qty']
result_dict[f'fp{z}'] = dictionary['b'][z - 1]['fp']
res.append(result_dict)
b
в исходном виде.res = []
for dictionary in d_list: # * 100_000:
result_dict = {'a': dictionary['a'],
'c': dictionary['c'],
'qty1': False, 'fp1': False,
'qty2': False, 'fp2': False,
'qty3': False, 'fp3': False
}
if isinstance(dictionary['b'], list):
for z in range(1, len(dictionary['b']) - 1):
result_dict[f'qty{z}'] = dictionary['b'][z - 1]['qty']
result_dict[f'fp{z}'] = dictionary['b'][z - 1]['fp']
res.append(result_dict)