forked from Pavel_Durov/python_bot
add structure to code
This commit is contained in:
27
handlers/time_new_year.py
Normal file
27
handlers/time_new_year.py
Normal file
@@ -0,0 +1,27 @@
|
||||
from aiogram import types, Dispatcher
|
||||
from create_bot import dp, bot
|
||||
import datetime
|
||||
|
||||
@dp.message_handler(commands=["time"])
|
||||
async def send_time(message: types.Message):
|
||||
new_year = datetime.datetime(2022, 12, 31) #дата нового года
|
||||
ct = datetime.datetime.now() #датавремя
|
||||
cd = datetime.datetime.now().strftime("%d/%m/%Y") #дата (д,м,г)
|
||||
ct1 = ct+datetime.timedelta(hours=15) # +14 часов от сервера
|
||||
ct2 = ct1.strftime('%H:%M') # форматирует датувремя просто во время(ч,м)
|
||||
raznitsa = (new_year - ct).days #отнимает от нг текущее время и получаем разницу в днях
|
||||
|
||||
days = ['день', 'дня', 'дней']
|
||||
if raznitsa % 10 == 1 and raznitsa % 100 != 11:
|
||||
p = 0
|
||||
elif 2 <= raznitsa % 10 <= 4 and (raznitsa % 100 < 10 or raznitsa % 100 >= 20):
|
||||
p = 1
|
||||
else:
|
||||
p = 2
|
||||
num=(str(raznitsa) + ' ' + days[p])
|
||||
|
||||
await message.reply(f'Сегодня {cd} \nВремя: {ct2} \nДо Нового Года осталось {num}')
|
||||
|
||||
|
||||
def register_handlers_time(dp: Dispatcher):
|
||||
dp.register_message_handler(send_time)
|
||||
Reference in New Issue
Block a user