TGTGInsighttelegram intelligenceLIVE / telegram public index
← Python Заметки

TGINSIGHT SIMILAR POSTS

Најди сличен содржај

Изворен канал @pythonotes · Post #418 · 9 мар.

Оператор pipe позволяет писать более компактный код, реализуя логику объединения данных (Union). Важно помнить, что его поведение зависит от контекста. Побитовые операции (логическое OR) result = 5 | 3 # 5 (0101) | 3 (0011) = 7 (0111) Самое главное - не путать с оператором or, это другое! Объединение множеств set_a = {1, 2, 3} set_b = {3, 4, 5} set_c = set_a | set_b # {1, 2, 3, 4, 5} set_c |= {5, 6} # {1, 2, 3, 4, 5, 6} Слияние словарей dict_1 = {"a": 1, "b": 2} dict_2 = {"b": 3, "c": 4} merged = dict_1 | dict_2 # {'a': 1, 'b': 3, 'c': 4} merged |= {"d": 5} # {'a': 1, 'b': 3, 'c': 4, 'd': 5} Аннотации типов, заменяет Union def process_data(value: int | str) -> None: print(value) Допустимо использовать в isinstance или issubclass isinstance(3, int | float) # True Паттерн-матчинг status_code = 404 match status_code: case 200 | 201 | 204: print("OK") case 400 | 404 | 500: print("ERROR") Для использования в своих классах требуется переопределить метод __or__ Так же нашел библиотеку pipe которая добавляет еще много возможностей. Рекомендую ознакомиться ;) #basic

Hashtags

Резултати

Пронајдени 1 слични објави

Пребарај: #bedtime

当前筛选 #bedtime清除筛选
JS Organization

@jsorganization · Post #456 · 07.07.2024 г., 09:32

Set Bed Time / Restrictions For Command Use Between 12 AM To 6 AM Bangladesh Time 🗓 TBC PYTHON CODE🤖 Command Name : YOUR COMMAND NAME Code : JS_Organizations = libs.dateandtime.now('Asia/Dhaka') hours = int(JS_Organizations['time'].split(':')[0]) minutes = int(JS_Organizations['time'].split(':')[1]) seconds = int(JS_Organizations['time'].split(':')[2]) bed_time_start = 0 # 12 AM in 24-hour format bed_time_end = 6 # 6 AM in 24-hour format if hours >= bed_time_start and hours < bed_time_end: remaining_hours = bed_time_end - hours - 1 remaining_minutes = 60 - minutes remaining_seconds = 60 - seconds ampm = 'AM' if hours < 12 else 'PM' hours12 = hours % 12 if hours12 == 0: hours12 = 12 remaining_time = f"<b>{remaining_hours} hours, {remaining_minutes} minutes, {remaining_seconds} seconds</b>" user_first_name = message.from_user.first_name message = ( f"<b>👋 Hey {user_first_name}</b>\n" f"<b>━━━━━━━━•❅•°•❈•°•❅•━━━━━━━━\n" f"It is Bed Time 🛏️\n" f"So You Cannot Use This Button From 12:00 AM To 6:00 AM in Bangladesh Time\n" f"Current Time: {hours12}:{minutes:02} {ampm}</b>\n" f"<b>━━━━━━━━•❅•°•❈•°•❅•━━━━━━━━\n" f"Come Back After: {remaining_time}</b>\n" f"<b>━━━━━━━━•❅•°•❈•°•❅•━━━━━━━━</b>" ) bot.sendMessage(chat_id=message.chat.id, text=message, parse_mode="HTML") else: #YOUR COMMAND Main CODE IS HERE, Or bot.sendMessage("Now Up Time") Paste this code above the code of your command! And enter your code below! You Can Change Your Timezone And Bed Time ⏱ If You Post This In Your Channel. please Mention Our Channel Name For Credit #BedTime#RestrictionTime#Time#TBC#JSOrganization © Copyright : @JSOrganization ❓ Question/Error : @itsSowrov