From 42661d863d852def0a1c29318d8c83fe49d28b42 Mon Sep 17 00:00:00 2001 From: Ceda EI Date: Thu, 4 Oct 2018 01:28:28 +0530 Subject: [PATCH] Add lock.py to send custom lock and unlock messages. --- lock.py | 30 ++++++++++++++++++++++++++++++ sample.config.py | 5 +++++ 2 files changed, 35 insertions(+) create mode 100644 lock.py diff --git a/lock.py b/lock.py new file mode 100644 index 0000000..f055dd1 --- /dev/null +++ b/lock.py @@ -0,0 +1,30 @@ +#!/usr/bin/env python3 + +import telegram +import sys +import datetime + +try: + import config +except ImportError: + print("Missing Config. Exiting.") + exit() + +bot = telegram.Bot(token=config.api_key) + +if len(sys.argv) != 2: + print("Invalid number of parameters") + exit(1) + +arg = sys.argv[1] +if arg == "lock": + today = datetime.datetime.today() + text = today.strftime(config.lock_message) + bot.send_message(chat_id=config.master_id, text=text) +elif arg == "unlock": + today = datetime.datetime.today() + text = today.strftime(config.lock_message) + bot.send_message(chat_id=config.master_id, text=text) +else: + print("Wrong parameter. Exiting.") + exit(1) diff --git a/sample.config.py b/sample.config.py index d3075d7..2f38a5e 100644 --- a/sample.config.py +++ b/sample.config.py @@ -13,3 +13,8 @@ lock = "xautolock -locknow" # Put the name of process that is running only when the screen is # locked. lock_process = "i3lock" + +# Lock and unlock message. The date is parsed according to strftime. +# Check man strftime or http://strftime.org/ +lock_message = "You have locked your system - %c" +unlock_message = "You have unlocked your system - %c"