#alarm not hitting the mark

55 messages · Page 1 of 1 (latest)

bold shard
#
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?
astral coral
#

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

bold shard
#

... shit,

#

alright, I think I can find a workaround

bold shard
#

yet it keeps being regiestered as 0

astral coral
#

!eval int("00")

formal edgeBOT
bold shard
#

yeah, i see the issue

#

best solution I can think of at the moment is tupples

astral coral
#

!exec ```py
seconds = 0
print(f"Seconds {seconds:02}")

formal edgeBOT
bold shard
#

ah

#

i see

astral coral
#

You can use formatting in the f-strings

bold shard
#

thanks

astral coral
#

0 to 0 pad, 2 to set the pad size

bold shard
#

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

astral coral
#

I dunno what that is so I'm not sure how it works

bold shard
#

oh

#

alright, thanks nonetheless

astral coral
#

Why is there a comma???

#

Feel like a file path shouldn't have a comma in it

bold shard
#

well, cause thats the file name

astral coral
#

Ok well /path seems odd, why are you starting with a slash?

bold shard
#

from example I caught on stack overflow

astral coral
#

Where is the file relative to your python file?

#

Is it in the same folder?

bold shard
#

yes

surreal belfry
#

try using an older version of the playsound library, the recent versions are little buggy i.e got this info from stackOverFlow.

astral coral
#

The /path bit isn't necessary

bold shard
#

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```
astral coral
#

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...

bold shard
#

gonna try one last thing

#

one sec

astral coral
#

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

bold shard
#

 Error 275 for command:
        open "alarm\woz.mp3"
    Cannot find the specified file.  Make sure the path and filename are correct.```
astral coral
#
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

bold shard
#

alright

#

PermissionError: [Errno 13] Permission denied: 'C:\Users\Kenne\PycharmProjects\tools and rules\alarm'

#

im outta ideas

astral coral
#

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())
bold shard
#

Works now