mirror of
				https://gitlab.com/ceda_ei/pc-monitor-bot
				synced 2025-10-31 06:00:04 +01:00 
			
		
		
		
	Add lock.py to send custom lock and unlock messages.
This commit is contained in:
		
							
								
								
									
										30
									
								
								lock.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										30
									
								
								lock.py
									
									
									
									
									
										Normal file
									
								
							| @@ -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) | ||||||
| @@ -13,3 +13,8 @@ lock = "xautolock -locknow" | |||||||
| # Put the name of process that is running only when the screen is | # Put the name of process that is running only when the screen is | ||||||
| # locked. | # locked. | ||||||
| lock_process = "i3lock" | 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" | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user