Skip to content

Instantly share code, notes, and snippets.

@taoky
Created July 19, 2022 15:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save taoky/b599196507060c19deaab918357be4a8 to your computer and use it in GitHub Desktop.
Save taoky/b599196507060c19deaab918357be4a8 to your computer and use it in GitHub Desktop.
Sleep timer
#!/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()
[Unit]
Description=Notify user when it's too late.
[Service]
Type=oneshot
ExecStart=/home/username/scripts/sleep-timer/script.py
[Install]
WantedBy=default.target
[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