import datetime
import time
from playsound import playsound
currentDate = datetime.datetime.now()
# countdown
# input time in seconds, minutues, and hours (note to use 24 hour system)
set_hour = int(input("Enter the time in hours: "))
set_minute = int(input("Enter the time in minute: "))
set_second = int(input("Enter the time in seconds: "))
# Infinite Loop
while True:
# Set Alarm
set_alarm_time = f"{set_hour}:{set_minute}:{set_second}"
# Wait for one seconds
time.sleep(1)
# Get current time
current_time = datetime.datetime.now().strftime("%H:%M:%S")
print("Current Time: " + current_time + " | Set Time: " + set_alarm_time)
# Check whether set alarm is equal to current time or not
if current_time == set_alarm_time:
print("Time is up")
# Playing sound
playsound("/path/woz, action.mp3")```
trying to get an alarm clock working on a python file, but the thing is refusing to have the condition of
```py
current_time == set_alarm_time```
any ideas?
#alarm not hitting the mark
55 messages · Page 1 of 1 (latest)
What inputs have you used to set the alarm?
Notice how current time has seconds 00 but my set time has 0, so they'll never be equal because the current time is zero padding the numbers while set time is not.
And when I zero pad it, the alarm works
for seconds, i always punched in 00
yet it keeps being regiestered as 0
!eval int("00")
✅ Eval - Success
>>> int("00")
0
Completed in 0.0336 milliseconds
!exec ```py
seconds = 0
print(f"Seconds {seconds:02}")
@astral coral
✅ Exec - Success (Super User 🦸)
Seconds 00
!exec modules | Completed in 0.0214 milliseconds
You can use formatting in the f-strings
thanks
0 to 0 pad, 2 to set the pad size
thanks,
but now ive got a different dillema
playsound is kind of busted
i have the designated audio track in the folder with the file
I dunno what that is so I'm not sure how it works
well, cause thats the file name
Ok well /path seems odd, why are you starting with a slash?
from example I caught on stack overflow
yes
try using an older version of the playsound library, the recent versions are little buggy i.e got this info from stackOverFlow.
Traceback (most recent call last):
File "C:\Users\Kenne\PycharmProjects\tools and rules\alarm\alarm clock.py", line 29, in <module>
playsound("woz action.mp3")
File "C:\kenneth\Python\Lib\site-packages\playsound.py", line 41, in _playsoundWin
copy(sound, tempPath)
File "C:\kenneth\Python\Lib\shutil.py", line 419, in copy
copyfile(src, dst, follow_symlinks=follow_symlinks)
File "C:\kenneth\Python\Lib\shutil.py", line 256, in copyfile
with open(src, 'rb') as fsrc:
^^^^^^^^^^^^^^^
FileNotFoundError: [Errno 2] No such file or directory: 'woz action.mp3'
Process finished with exit code 1```
Hmmm
Maybe you're running from a different location... Try r"alarm\woz action.mp3
You might also try getting rid of the space inside the file name...
same result
gonna try one last thing
one sec
Without knowing where you're running the code from it's hard to say what the path to the file should look like.
You could import pathlib and use it to figure out the paths
Error 275 for command:
open "alarm\woz.mp3"
Cannot find the specified file. Make sure the path and filename are correct.```
from pathlib import Path
print(Path().resolve())
That'll tell you where you're working from
Then we can build the path to the file from there
alright
PermissionError: [Errno 13] Permission denied: 'C:\Users\Kenne\PycharmProjects\tools and rules\alarm'
im outta ideas
I just meant to print that lol it's a folder so you can't open it as a file. But now we know that you're inside the alarm folder...
Try this
playsound((Path() / "woz, action.mp3").resolve())
Works now