From 5872be6a26bd5f5f6a71f5db440a413e720b24a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20Ru=CC=88egg?= Date: Fri, 14 Feb 2020 06:18:41 +0100 Subject: [PATCH] fix parsing, setup - Fixed parsing of absolute time with seconds - Allow to run multiple workflows --- README.md | 23 +++++++++++++++++++---- info.plist | 54 +++++++++++++++++++++++++++++------------------------- 2 files changed, 48 insertions(+), 29 deletions(-) diff --git a/README.md b/README.md index 454c4dd..ae1228c 100644 --- a/README.md +++ b/README.md @@ -6,28 +6,43 @@ Show an alert on the screen and a notification with Alfred: **[Download the workflow][download]** + ## Absolute times: * `07:51:38` * `14:00` * `7:40PM` + ## Relative times: * `5` corresponds to seconds * `180s` corresponds to 3 minutes * `7m` corresponds to 7 minutes * `12h` corresponds to 12 hours + ## Examples * `180 Egg is finished * `12:00 Don't forget to eat lunch -![](screenshots/AbsoluteTime.png) +## Screen shots + +![Absolut](screenshots/AbsoluteTime.png) + +![Relative](screenshots/RelativeTime.png) + +![Alert](screenshots/Alert.png) + + +## History -![](screenshots/RelativeTime.png) +* Version 1.0.1 + - Fixed parsing of absolute time with seconds + - Allow to run multiple workflows -![](screenshots/Alert.png) +* Version 1.0.0 + - Initial Release -[download]: https://github.com/Macintron/Alfred-Workflow-Alert/releases/download/v1.0.0/Alert.v1.0.0.alfredworkflow +[download]: https://github.com/Macintron/Alfred-Workflow-Alert/releases/download/v1.0.1/Alert.v1.0.1.alfredworkflow [alfred]: http://www.alfredapp.com \ No newline at end of file diff --git a/info.plist b/info.plist index 13f6589..af22c74 100644 --- a/info.plist +++ b/info.plist @@ -59,7 +59,7 @@ config concurrently - + escaping 68 script @@ -72,23 +72,18 @@ def parse_time(time_str, now = datetime.datetime.now()): return int(time_str) if time_str.find(':') >= 0: + # absolute time try: format = '' if time_str.lower().find('am') > 0 or time_str.lower().find('pm') > 0: format = '%I:%M%p' else: - format = '%M:%S' + format = '%H:%M' if time_str.count(':') > 1: - format = '%H:' + format - else: - raise RuntimeError("Parse Error time '{}' has invalid number of ':'".format(time_str)) + format += ':%S' time_struct = time.strptime(time_str, format) #sys.stderr.write("parse {}\n".format(time_struct)) - #date_time = datetime.fromtimestamp(mktime(time_struct)) - #delta = date_time - datetime.datetime.now() - #sys.stderr.write("delta {}\n".format(delta)) - seconds_since_midnight = int((now - now.replace(hour=0, minute=0, second=0, microsecond=0)).total_seconds()) secs = time_struct.tm_hour*3600 + time_struct.tm_min*60 + time_struct.tm_sec secs -= seconds_since_midnight @@ -97,20 +92,22 @@ def parse_time(time_str, now = datetime.datetime.now()): return secs except Exception as e: sys.stderr.write("Parse Error {}\n".format(e)) - return 10 - lookup = { - 's': 1, - 'm': 60, - 'h': 60*60, - } - for unit, factor in lookup.items(): - if time_str.endswith(unit): - firstPart = time_str[:-(len(unit))] - if firstPart.isdigit(): - return int(firstPart) * factor + else: + # relative time + lookup = { + 's': 1, + 'm': 60, + 'h': 60*60, + } + for unit, factor in lookup.items(): + if time_str.endswith(unit): + firstPart = time_str[:-(len(unit))] + if firstPart.isdigit(): + return int(firstPart) * factor - return 10 + return -1 + def parse_test(): now = datetime.datetime.now() @@ -125,7 +122,7 @@ def parse_test(): ('7:40AM', time_diff(7*3600 + 40*60)), ('7:40PM', time_diff(19*3600 + 40*60)), ('4:30pm', time_diff(16*3600 + 30*60)), - ('22:19:55', time_diff(22*3600 + 19*60 + 55)), + ('22:19', time_diff(22*3600 + 19*60)), ('12:30PM', time_diff(12*3600 + 30*60)), ('10:12:45', time_diff(10*3600 + 12*60 + 45)), ('17:08:00', time_diff(17*3600 + 8*60)), @@ -134,6 +131,9 @@ def parse_test(): ('15s', 15), ('23m', 23*60), ('19h', 19*3600), + ('4A', -1), + ('A4', -1), + ('10:12:45.123', -1), ] for time_str, expected in test_data: @@ -160,7 +160,7 @@ if __name__ == '__main__': if len(args) > 1: timeStr = args[0].strip() message = ' '.join(args[1:]) - elif len(args) == 0: + elif len(args) == 1: parse_test() sys.exit(0) @@ -168,6 +168,10 @@ if __name__ == '__main__': sys.stderr.write("message '{}'\n".format(message)) timeout = parse_time(timeStr) + if timeout < 0: + sys.stderr.write("Invalid time\n") + sys.exit(0) + sys.stderr.write("timeout '{}'\n".format(timeout)) time.sleep(timeout) print(message.encode('utf8')) @@ -212,7 +216,7 @@ if __name__ == '__main__': lastpathcomponent onlyshowifquerypopulated - + removeextension text @@ -306,7 +310,7 @@ Examples variablesdontexport version - 1.0.0 + 1.0.1 webaddress https://github.com/Macintron/Alfred-Workflow-Alert