from multiprocessing import Process
from flask import Flask
from aiogram import Bot, Dispatcher, executor, types
import config
app = Flask(import_name=__name__)
bot = Bot(token=config.BOT_TOKEN)
dispatcher = Dispatcher(bot=bot)
def bot_start_polling():
executor.start_polling(dispatcher=dispatcher, skip_updates=True)
@dispatcher.message_handler(commands=['start'])
async def bot_handler_start(message: types.Message):
await message.reply('Foo')
@app.get(rule='/start_bot')
def start_bot():
bot_process = Process(target=bot_start_polling)
bot_process.start()
return str(bot_process.pid)
if __name__ == '__main__':
app.run()
students = ['Вася', 'Петя', 'Ваня', 'Света']
present_students = ['Вася', 'Петя']
if len(students) == len(present_students):
print('Все студенты на месте. Начинаем занятие!')
else:
print('Отсутствующие к экзамену допущены не будут')
def expand(data: list):
for value in data:
if hasattr(value, '__iter__') and not isinstance(value, (str, bytes)):
yield from expand(value)
else:
yield value
data = [[['Volvo', 'Xc90', '2017', 'Gray', '2.0L'], 'YV4102XK8H1144180', 'Copart', '69990071', 'Run And Drive', 'Side', '33554 мили (Actual)', '07.02.2022'], [['Volvo', 'Xc90', '2017', 'Gray', '2.0L'], 'YV4102XK8H1144180', 'Copart', '69990071', 'Run And Drive', 'Side', '33554 мили (Actual)', '07.02.2022']]
expanded_data = []
for d in data:
expanded_data.append(list(expand(data)))
[['Volvo', 'Xc90', '2017', 'Gray', '2.0L', 'YV4102XK8H1144180', 'Copart', '69990071', 'Run And Drive', 'Side', '33554 мили (Actual)', '07.02.2022', 'Volvo', 'Xc90', '2017', 'Gray', '2.0L', 'YV4102XK8H1144180', 'Copart', '69990071', 'Run And Drive', 'Side', '33554 мили (Actual)', '07.02.2022'], ['Volvo', 'Xc90', '2017', 'Gray', '2.0L', 'YV4102XK8H1144180', 'Copart', '69990071', 'Run And Drive', 'Side', '33554 мили (Actual)', '07.02.2022', 'Volvo', 'Xc90', '2017', 'Gray', '2.0L', 'YV4102XK8H1144180', 'Copart', '69990071', 'Run And Drive', 'Side', '33554 мили (Actual)', '07.02.2022']]
from typing import List, Iterable, Any
def super_zip(*args: Iterable) -> List[tuple]:
count = len(args)
lengths = {i: len(v) for i, v in enumerate(args)}
max_values_index = max(lengths, key=lengths.get)
def extract(chunk_index: int, value_index: int) -> Any:
try:
return args[chunk_index][value_index]
except IndexError:
return None
return [
tuple(extract(ci, vi) for ci in range(count))
for vi in range(lengths[max_values_index])
]
super_zip('abc', [1, 2, 3], ('Z', 'X', 'C'))
# [('a', 1, 'Z'), ('b', 2, 'X'), ('c', 3, 'C')]
super_zip('abc', [1, 2, 3, 4], ('Z', 'X'))
# [('a', 1, 'Z'), ('b', 2, 'X'), ('c', 3, None), (None, 4, None)]
super_zip('abc')
# [('a',), ('b',), ('c',)]
import logging
while True:
try:
executor.start_polling(dispatcher=dispatcher, skip_updates=True)
except (KeyboardInterrupt, SystemExit):
break
except Exception:
logging.exception('polling error')