Skip to content

Commit

Permalink
fix parsing, setup
Browse files Browse the repository at this point in the history
- Fixed parsing of absolute time with seconds
- Allow to run multiple workflows
  • Loading branch information
Christian Rüegg authored and Christian Rüegg committed Feb 14, 2020
1 parent 7785a52 commit 5872be6
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 29 deletions.
23 changes: 19 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
54 changes: 29 additions & 25 deletions info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
<key>config</key>
<dict>
<key>concurrently</key>
<false/>
<true/>
<key>escaping</key>
<integer>68</integer>
<key>script</key>
Expand All @@ -72,23 +72,18 @@ def parse_time(time_str, now = datetime.datetime.now()):
return int(time_str)
if time_str.find(':') &gt;= 0:
# absolute time
try:
format = ''
if time_str.lower().find('am') &gt; 0 or time_str.lower().find('pm') &gt; 0:
format = '%I:%M%p'
else:
format = '%M:%S'
format = '%H:%M'
if time_str.count(':') &gt; 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
Expand All @@ -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()
Expand All @@ -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)),
Expand All @@ -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:
Expand All @@ -160,14 +160,18 @@ if __name__ == '__main__':
if len(args) &gt; 1:
timeStr = args[0].strip()
message = ' '.join(args[1:])
elif len(args) == 0:
elif len(args) == 1:
parse_test()
sys.exit(0)
sys.stderr.write("timeStr '{}'\n".format(timeStr))
sys.stderr.write("message '{}'\n".format(message))
timeout = parse_time(timeStr)
if timeout &lt; 0:
sys.stderr.write("Invalid time\n")
sys.exit(0)
sys.stderr.write("timeout '{}'\n".format(timeout))
time.sleep(timeout)
print(message.encode('utf8'))</string>
Expand Down Expand Up @@ -212,7 +216,7 @@ if __name__ == '__main__':
<key>lastpathcomponent</key>
<false/>
<key>onlyshowifquerypopulated</key>
<false/>
<true/>
<key>removeextension</key>
<false/>
<key>text</key>
Expand Down Expand Up @@ -306,7 +310,7 @@ Examples
<key>variablesdontexport</key>
<array/>
<key>version</key>
<string>1.0.0</string>
<string>1.0.1</string>
<key>webaddress</key>
<string>https://github.com/Macintron/Alfred-Workflow-Alert</string>
</dict>
Expand Down

0 comments on commit 5872be6

Please sign in to comment.