r/pythonhelp • u/Sea-Personality-666 • Jul 13 '26
how to turn on and off DND?
import time
from datetime import datetime
from plyer import notification
print("_Main_menu_")
print("1. set alarm")
print("2. set timer") #Haven't added yet plz ignore
while True:
MenuChoice = input("select an option: ")
try:
MenuChoice = int(MenuChoice)
except ValueError:
print("Invalid Option")
else:
MenuChoice = int(MenuChoice)
if MenuChoice == 1 or MenuChoice == 2:
break
else: print("Invalid Option")
Time = datetime.now().time()
Time = str(Time)
print(Time[:-10])
if MenuChoice == 1:
while True:
Alarm = input("Set Time(HH:MM): ")
try:
Hour, Min = Alarm.split(":", 1)
Min = int(Min)
Hour = int(Hour)
Valid = False
Valid1 = False
if Min > 59:
print("Min can't be greater than 59")
elif Min < 0:
print("Min can't be less than 0")
else: Valid = True
if Hour > 23:
print("Hour can't be greater than 23")
elif Hour < 0:
print("Hour can't be less than 0")
else: Valid1 = True
if Valid == True and Valid1 == True:
print("Lock in until",Alarm)
#turn on DND
while True:
TimeNow = datetime.now().time() #Loops until Alarm = TimeNow
TimeNow = str(TimeNow)[:-10]
time.sleep(.5)
if TimeNow == Alarm:
break
#Turn off DND
notification.notify(
title="Time to take a break",
message=f"it's {Alarm}, time to take a break",
timeout=5
)
break
except ValueError:
print("Invalid")Above is my focus alarm I'm working on, could someone help with adding DND?
1
Upvotes
•
u/AutoModerator Jul 13 '26
To give us the best chance to help you, please include any relevant code.
Note. Please do not submit images of your code. Instead, for shorter code you can use Reddit markdown (4 spaces or backticks, see this Formatting Guide). If you have formatting issues or want to post longer sections of code, please use Privatebin, GitHub or Compiler Explorer.
I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.
2
u/FoolsSeldom Jul 13 '26
Surely
DND("Do Not Disturb") is simply a boolean state. No sound if it isTrue. What do you need help on exactly?Note:
if Valid == True and Valid1 == True:is a little redundant, you only needif Valid and Valid1:By the way, in Python, the convention is to use all lowercase for regular variable names (and functions). Also, come up with more descriptive variable names.
Example (not checked):
1
u/cvx_mbs Jul 13 '26
what's DND? Dungeons 'n' Dragons? Drugs for Neglected Diseases? Dad 'n' Daughter? Department of National Defence?