Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
Smarter Alarm Clock
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package Registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
surajss2
Smarter Alarm Clock
Commits
27cc5786
Commit
27cc5786
authored
2 years ago
by
SurajSSingh
Browse files
Options
Downloads
Patches
Plain Diff
Organized Alarm scripts
parent
3d6b2065
Branches
master
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
alarm.py
+56
-0
56 additions, 0 deletions
alarm.py
simple_alarm_clock.py
+7
-73
7 additions, 73 deletions
simple_alarm_clock.py
smart_alarm_clock.py
+5
-0
5 additions, 0 deletions
smart_alarm_clock.py
with
68 additions
and
73 deletions
alarm.py
+
56
−
0
View file @
27cc5786
...
...
@@ -30,3 +30,59 @@
#
#
#
from
enum
import
Enum
,
auto
from
datetime
import
time
,
datetime
class
AlarmState
(
Enum
):
SET
=
auto
(),
RUNNING
=
auto
(),
PLAYING
=
auto
(),
SNOOZED
=
auto
(),
DEACTIVATED
=
auto
(),
class
BaseAlarmClock
:
_current_state
:
AlarmState
_wake_time
:
time
def
__init__
(
self
,
wake_time
:
time
=
datetime
.
now
().
time
()):
self
.
_wake_time
=
wake_time
self
.
_current_state
=
AlarmState
.
DEACTIVATED
@property
def
current_state
(
self
):
return
self
.
_current_state
@property
def
wake_time
(
self
):
return
self
.
_wake_time
def
set_alarm
(
self
,
wake_time
:
time
)
->
time
:
print
(
f
"
SETTING ALARM to:
{
wake_time
}
"
)
self
.
_current_state
=
AlarmState
.
SET
self
.
_wake_time
=
wake_time
return
self
.
_wake_time
def
start_alarm
(
self
)
->
None
:
print
(
"
STARTING ALARM
"
)
self
.
_current_state
=
AlarmState
.
RUNNING
def
sound_alarm
(
self
)
->
None
:
print
(
"
SOUNDING ALARM
"
)
self
.
_current_state
=
AlarmState
.
PLAYING
def
snooze_alarm
(
self
)
->
None
:
print
(
"
SNOOZING ALARM
"
)
self
.
_current_state
=
AlarmState
.
SNOOZED
def
stop_alarm
(
self
,
deactivate
:
bool
=
True
)
->
None
:
print
(
"
STOPPING ALARM
"
)
if
self
.
_current_state
is
AlarmState
.
PLAYING
:
print
(
"
STOPPED PLAYING ALARM
"
)
self
.
_current_state
=
AlarmState
.
DEACTIVATED
if
deactivate
else
AlarmState
.
SET
def
alarm_check_reached
(
self
,
current_time
:
time
=
datetime
.
now
().
time
())
->
bool
:
# result = current_time >= self.wake_time if self.current_state is AlarmState.RUNNING else False
# print(f"{result = }")
return
current_time
>=
self
.
_wake_time
if
self
.
_current_state
is
AlarmState
.
RUNNING
else
False
This diff is collapsed.
Click to expand it.
simple_alarm_clock.py
+
7
−
73
View file @
27cc5786
from
dataclasses
import
dataclass
from
enum
import
Enum
,
auto
from
alarm
import
BaseAlarmClock
,
AlarmState
from
datetime
import
time
,
datetime
from
typing
import
Optional
,
Any
from
time
import
sleep
from
pynput
import
keyboard
from
pynput.keyboard
import
Key
,
Controller
# Simple Alarm Clock has 5 functionalities:
# 1. Set Alarm Time - Set the time for the alarm to sound, does NOT make the alarm active
...
...
@@ -14,78 +11,12 @@ from pynput.keyboard import Key, Controller
# 5. Stop Alarm - If the alarm is active or is playing, stop the alarm (deactivate state)
ALARM_TIME
=
time
(
19
,
13
,
0
)
SNOOZE_SEC
=
5
SNOOZE_KEY
=
keyboard
.
Key
.
up
ALARM_OFF_KEY
=
keyboard
.
Key
.
esc
SNOOZE_SEC
=
5
class
AlarmState
(
Enum
):
SET
=
auto
(),
RUNNING
=
auto
(),
PLAYING
=
auto
(),
SNOOZED
=
auto
(),
DEACTIVATED
=
auto
(),
@dataclass
class
BaseAlarmClock
:
# player: Optional
wake_time
:
time
current_state
:
AlarmState
=
AlarmState
.
DEACTIVATED
def
set_alarm
(
self
,
wake_time
:
time
)
->
time
:
print
(
f
"
SETTING ALARM to:
{
wake_time
}
"
)
self
.
current_state
=
AlarmState
.
SET
self
.
wake_time
=
wake_time
return
self
.
wake_time
def
start_alarm
(
self
,
check_frequency
:
int
=
1
):
print
(
"
STARTING ALARM
"
)
self
.
current_state
=
AlarmState
.
RUNNING
# now = datetime.now().time()
# if now >= self.wake_time:
# return False
# sleep_time_amount = max(check_frequency, 1)
# while now < self.wake_time:
# # Sleep for some time
# sleep(sleep_time_amount)
# now = datetime.now().time()
# self.sound_alarm()
# return True
def
sound_alarm
(
self
):
print
(
"
SOUNDING ALARM
"
)
self
.
current_state
=
AlarmState
.
PLAYING
# if sound is not None:
# self.player.set_media(sound)
# self.player.audio_set_volume(volume)
# self.player.play()
def
snooze_alarm
(
self
,
snooze_time
:
int
=
SNOOZE_SEC
):
print
(
"
SNOOZING ALARM
"
)
self
.
current_state
=
AlarmState
.
SNOOZED
# self.player.pause()
# Maybe make this async later
sleep
(
snooze_time
)
# self.player.play()
if
self
.
current_state
is
AlarmState
.
SNOOZED
:
self
.
sound_alarm
()
def
stop_alarm
(
self
,
deactivate
:
bool
=
True
):
print
(
"
STOPPING ALARM
"
)
if
self
.
current_state
is
AlarmState
.
PLAYING
:
print
(
"
STOPPED PLAYING ALARM
"
)
# self.player.stop()
self
.
current_state
=
AlarmState
.
DEACTIVATED
if
deactivate
else
AlarmState
.
SET
def
alarm_check_reached
(
self
,
current_time
=
datetime
.
now
().
time
())
->
bool
:
result
=
current_time
>=
self
.
wake_time
if
self
.
current_state
is
AlarmState
.
RUNNING
else
False
print
(
f
"
{
result
=
}
"
)
return
result
def
simple_alarm_mode
(
alarm_time
):
alarm_clock
=
BaseAlarmClock
(
alarm_time
)
def
simple_alarm_mode
(
alarm_clock
:
BaseAlarmClock
):
alarm_clock
.
start_alarm
()
while
not
alarm_clock
.
alarm_check_reached
():
print
(
f
"
ALARM SLEEPING @:
{
datetime
.
now
().
time
()
}
"
)
...
...
@@ -99,8 +30,11 @@ def simple_alarm_mode(alarm_time):
break
elif
event
.
key
==
SNOOZE_KEY
:
alarm_clock
.
snooze_alarm
()
sleep
(
SNOOZE_SEC
)
alarm_clock
.
sound_alarm
()
break
if
__name__
==
'
__main__
'
:
simple_alarm_mode
(
ALARM_TIME
)
alarm_clock
=
BaseAlarmClock
(
ALARM_TIME
)
simple_alarm_mode
(
alarm_clock
)
This diff is collapsed.
Click to expand it.
smart_alarm_clock.py
+
5
−
0
View file @
27cc5786
from
alarm
import
BaseAlarmClock
,
AlarmState
from
datetime
import
time
,
datetime
from
time
import
sleep
from
pynput
import
keyboard
import
vlc
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment