Skip to content

Commit 5872be6

Browse files
Christian RüeggChristian Rüegg
authored andcommitted
fix parsing, setup
- Fixed parsing of absolute time with seconds - Allow to run multiple workflows
1 parent 7785a52 commit 5872be6

File tree

2 files changed

+48
-29
lines changed

2 files changed

+48
-29
lines changed

README.md

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,28 +6,43 @@ Show an alert on the screen and a notification with Alfred:
66

77
**[Download the workflow][download]**
88

9+
910
## Absolute times:
1011
* `07:51:38`
1112
* `14:00`
1213
* `7:40PM`
1314

15+
1416
## Relative times:
1517
* `5` corresponds to seconds
1618
* `180s` corresponds to 3 minutes
1719
* `7m` corresponds to 7 minutes
1820
* `12h` corresponds to 12 hours
1921

22+
2023
## Examples
2124
* `180 Egg is finished
2225
* `12:00 Don't forget to eat lunch
2326

2427

25-
![](screenshots/AbsoluteTime.png)
28+
## Screen shots
29+
30+
![Absolut](screenshots/AbsoluteTime.png)
31+
32+
![Relative](screenshots/RelativeTime.png)
33+
34+
![Alert](screenshots/Alert.png)
35+
36+
37+
## History
2638

27-
![](screenshots/RelativeTime.png)
39+
* Version 1.0.1
40+
- Fixed parsing of absolute time with seconds
41+
- Allow to run multiple workflows
2842

29-
![](screenshots/Alert.png)
43+
* Version 1.0.0
44+
- Initial Release
3045

3146

32-
[download]: https://github.com/Macintron/Alfred-Workflow-Alert/releases/download/v1.0.0/Alert.v1.0.0.alfredworkflow
47+
[download]: https://github.com/Macintron/Alfred-Workflow-Alert/releases/download/v1.0.1/Alert.v1.0.1.alfredworkflow
3348
[alfred]: http://www.alfredapp.com

info.plist

Lines changed: 29 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@
5959
<key>config</key>
6060
<dict>
6161
<key>concurrently</key>
62-
<false/>
62+
<true/>
6363
<key>escaping</key>
6464
<integer>68</integer>
6565
<key>script</key>
@@ -72,23 +72,18 @@ def parse_time(time_str, now = datetime.datetime.now()):
7272
return int(time_str)
7373
7474
if time_str.find(':') &gt;= 0:
75+
# absolute time
7576
try:
7677
format = ''
7778
if time_str.lower().find('am') &gt; 0 or time_str.lower().find('pm') &gt; 0:
7879
format = '%I:%M%p'
7980
else:
80-
format = '%M:%S'
81+
format = '%H:%M'
8182
if time_str.count(':') &gt; 1:
82-
format = '%H:' + format
83-
else:
84-
raise RuntimeError("Parse Error time '{}' has invalid number of ':'".format(time_str))
83+
format += ':%S'
8584
8685
time_struct = time.strptime(time_str, format)
8786
#sys.stderr.write("parse {}\n".format(time_struct))
88-
#date_time = datetime.fromtimestamp(mktime(time_struct))
89-
#delta = date_time - datetime.datetime.now()
90-
#sys.stderr.write("delta {}\n".format(delta))
91-
9287
seconds_since_midnight = int((now - now.replace(hour=0, minute=0, second=0, microsecond=0)).total_seconds())
9388
secs = time_struct.tm_hour*3600 + time_struct.tm_min*60 + time_struct.tm_sec
9489
secs -= seconds_since_midnight
@@ -97,20 +92,22 @@ def parse_time(time_str, now = datetime.datetime.now()):
9792
return secs
9893
except Exception as e:
9994
sys.stderr.write("Parse Error {}\n".format(e))
100-
return 10
10195
102-
lookup = {
103-
's': 1,
104-
'm': 60,
105-
'h': 60*60,
106-
}
107-
for unit, factor in lookup.items():
108-
if time_str.endswith(unit):
109-
firstPart = time_str[:-(len(unit))]
110-
if firstPart.isdigit():
111-
return int(firstPart) * factor
96+
else:
97+
# relative time
98+
lookup = {
99+
's': 1,
100+
'm': 60,
101+
'h': 60*60,
102+
}
103+
for unit, factor in lookup.items():
104+
if time_str.endswith(unit):
105+
firstPart = time_str[:-(len(unit))]
106+
if firstPart.isdigit():
107+
return int(firstPart) * factor
112108
113-
return 10
109+
return -1
110+
114111
115112
def parse_test():
116113
now = datetime.datetime.now()
@@ -125,7 +122,7 @@ def parse_test():
125122
('7:40AM', time_diff(7*3600 + 40*60)),
126123
('7:40PM', time_diff(19*3600 + 40*60)),
127124
('4:30pm', time_diff(16*3600 + 30*60)),
128-
('22:19:55', time_diff(22*3600 + 19*60 + 55)),
125+
('22:19', time_diff(22*3600 + 19*60)),
129126
('12:30PM', time_diff(12*3600 + 30*60)),
130127
('10:12:45', time_diff(10*3600 + 12*60 + 45)),
131128
('17:08:00', time_diff(17*3600 + 8*60)),
@@ -134,6 +131,9 @@ def parse_test():
134131
('15s', 15),
135132
('23m', 23*60),
136133
('19h', 19*3600),
134+
('4A', -1),
135+
('A4', -1),
136+
('10:12:45.123', -1),
137137
]
138138
139139
for time_str, expected in test_data:
@@ -160,14 +160,18 @@ if __name__ == '__main__':
160160
if len(args) &gt; 1:
161161
timeStr = args[0].strip()
162162
message = ' '.join(args[1:])
163-
elif len(args) == 0:
163+
elif len(args) == 1:
164164
parse_test()
165165
sys.exit(0)
166166
167167
sys.stderr.write("timeStr '{}'\n".format(timeStr))
168168
sys.stderr.write("message '{}'\n".format(message))
169169
170170
timeout = parse_time(timeStr)
171+
if timeout &lt; 0:
172+
sys.stderr.write("Invalid time\n")
173+
sys.exit(0)
174+
171175
sys.stderr.write("timeout '{}'\n".format(timeout))
172176
time.sleep(timeout)
173177
print(message.encode('utf8'))</string>
@@ -212,7 +216,7 @@ if __name__ == '__main__':
212216
<key>lastpathcomponent</key>
213217
<false/>
214218
<key>onlyshowifquerypopulated</key>
215-
<false/>
219+
<true/>
216220
<key>removeextension</key>
217221
<false/>
218222
<key>text</key>
@@ -306,7 +310,7 @@ Examples
306310
<key>variablesdontexport</key>
307311
<array/>
308312
<key>version</key>
309-
<string>1.0.0</string>
313+
<string>1.0.1</string>
310314
<key>webaddress</key>
311315
<string>https://github.com/Macintron/Alfred-Workflow-Alert</string>
312316
</dict>

0 commit comments

Comments
 (0)