commit 2575907ef156686e64a91fec4d29f0c5dfdce90c Author: Augusto Gunsch Date: Mon May 23 16:25:33 2022 -0300 Initial commit diff --git a/README.md b/README.md new file mode 100644 index 0000000..6b56616 --- /dev/null +++ b/README.md @@ -0,0 +1,11 @@ +Simple script for limiting access time to certain applications. + +## Examples +- Only allow usage of newsboat from 8AM to 9AM: +``` +timeking '08:00-09:00' && newsboat +``` +- Allow newsboat from 8AM to 9AM and from 11AM to 12AM: +``` +timeking '08:00-09:00&11:00-12:00' && newsboat +``` diff --git a/timeking b/timeking new file mode 100755 index 0000000..43707b9 --- /dev/null +++ b/timeking @@ -0,0 +1,30 @@ +#!/bin/python3.9 +from datetime import datetime +from sys import argv, stderr +from os import system +import re + +rules = argv[1].split('&') + +pattern = re.compile(r'(\d{2}):(\d{2})-(\d{2}):(\d{2})') +now = datetime.now() + +nm = now.hour * 60 + now.minute + +for rule in rules: + m = pattern.match(rule) + if not m: + print('unrecognized time stamp "{}"'.format(rule), file=stderr) + exit(1) + + sh, sm, eh, em = map(int, m.groups()) + + sm = sh * 60 + sm + em = eh * 60 + em + + if nm >= sm and nm <= em: + exit(0) + +print('You are not supposed to access this program now', file=stderr) +system('notify-send -u critical "You are not supposed to access this program now"') +exit(2)