python_asyncio_course/6_tasks/6_7_04_warehouse.py

61 lines
2 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import asyncio
warehouse_store = {
"Диван": 15,
"Обеденный_стол": 10,
"Офисноересло": 25,
"Кофейный_столик": 12,
"Кровать": 8,
"Книжный_шкаф": 20,
"ТВ-тумба": 7,
"Шкаф": 9,
"Письменный_стол": 18,
"Тумбочка": 14,
"Комод": 11,
"Барный_стул": 22,
"Угловой_диван": 4,
"Двухъярусная_кровать": 3,
"Шезлонг": 2,
"Консольный_столик": 16,
"Кресло": 17,
"Туалетный_столик": 19,
"Книжный_стеллаж": 24,
"Банкетка": 10,
"Обеденный_стул": 28,
"Кресло-качалка": 15,
"Шкаф-купе": 18,
"Табуретка": 40,
"Стеллаж": 13,
"Кресло-мешок": 5,
"Кухонный_гарнитур": 6,
"Журнальный_столик": 8,
"Витрина": 7,
"Полка": 30,
}
order = {"Диван": 5, "Обеденный_стол": 3, "Табуретка": 50, "Гардероб": 1}
async def check_store(position: str, amount_needed: int):
amount_in_stock = warehouse_store.get(position)
if not amount_in_stock or amount_in_stock == 0:
asyncio.current_task().set_name(f"Отсутствует: {position}")
elif amount_in_stock < amount_needed:
asyncio.current_task().set_name(f"Частично в наличии: {position}")
elif amount_in_stock >= amount_needed:
asyncio.current_task().set_name(f"В наличии: {position}")
async def main():
tasks = [
asyncio.create_task(check_store(position, amount_needed))
for position, amount_needed in order.items()
]
done, _ = await asyncio.wait(tasks, return_when=asyncio.ALL_COMPLETED)
result_names = [done_task.get_name() for done_task in done]
result_names.sort()
for entry in result_names:
print(entry)
asyncio.run(main())