Created
July 19, 2022 15:54
-
-
Save taoky/b599196507060c19deaab918357be4a8 to your computer and use it in GitHub Desktop.
Sleep timer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
import datetime | |
# you need python-notify2 | |
import notify2 | |
import time | |
def main(): | |
now = datetime.datetime.now() | |
title = "Time Notification" | |
if now.hour >= 23 or now.hour <= 4: | |
contents = f"It's {now.hour}:{now.minute} now!" | |
else: | |
return | |
noti = notify2.Notification(title, contents) | |
# https://developer-old.gnome.org/notification-spec/#hints | |
# transient: When set the server will treat the notification as transient and by-pass the server's persistence capability, if it should exist. | |
noti.set_hint("transient", True) | |
noti.show() | |
if __name__ == "__main__": | |
notify2.init("sleep-timer") | |
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[Unit] | |
Description=Notify user when it's too late. | |
[Service] | |
Type=oneshot | |
ExecStart=/home/username/scripts/sleep-timer/script.py | |
[Install] | |
WantedBy=default.target |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[Unit] | |
Description="Systemd timer for sleep-timer" | |
[Timer] | |
OnCalendar=23,0,1,2,3,4:30 | |
[Install] | |
WantedBy=timers.target |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment