-
Notifications
You must be signed in to change notification settings - Fork 0
/
statusparser
executable file
·98 lines (80 loc) · 2.4 KB
/
statusparser
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#!/usr/bin/env python3
# Copyright (c) 2019 Benjamin Holt -- MIT License
"""
Parse only my status out of a team standup message
"""
import re
import statemachine as sm
#####
### Main ###
def main(args, env, in_file):
name = args[1] if len(args) >= 2 else "bholt"
parser = sm.StateMachine("top", tracer=-1)
# parser = sm.StateMachine("top", unrecognized=False)
# parser = sm.StateMachine("top", tracer=sm.Tracer(printer=lambda s: print(f"T: {s}")))
# parser = sm.StateMachine("top", tracer=2)
my_user = f"@{name}"
my_status = (sm.true_test, None, lambda i,_: f"> {i}")
other_user = sm.match_test(r"^@\w+$")
start_yesterday = {
"test": "1. What did you do yesterday?",
"dst": "yesterday",
"action": "_Yesterday:_",
}
start_today = {
"test": "2. What do you commit to today?",
"dst": "today",
"action": "_Today:_",
}
start_how_far = {
"test": "3. How far along are you? Do you think you'll finish soon?",
"dst": "top",
}
parser.build(
"top",
start_yesterday,
start_today,
((sm.true_test, None), {"tag":"Other line"}),
)
parser.build(
"yesterday",
start_today,
(my_user, "myYesterday"),
((sm.true_test, None), {"tag":"Other line"}),
)
parser.build(
"myYesterday",
start_today,
(other_user, "yesterday"),
my_status,
)
parser.build(
"today",
start_how_far,
(my_user, "myToday"),
((sm.true_test, None), {"tag":"Other line"}),
)
parser.build(
"myToday",
start_how_far,
(other_user, "today"),
my_status,
)
status = ["*Check-in*",]
for out in parser.parse(( l.rstrip() for l in in_file )):
status.append(out)
print("\n".join(status))
# print("\n".join(parser.tracer.format_trace()))
#####
#####
if __name__ == "__main__":
import os, sys
if len(sys.argv) >= 2 and sys.argv[1] in ["-h", "--help"]:
h = """Simple parser for extracting my status from a standup summary form; not likely to be useful to anyone else.
Usage: pbpaste | statusparser [name] Extract 'yesterday' and 'today' status for name; defaults to "bholt"
"""
print(h)
sys.exit(0)
_xit = main(sys.argv, os.environ, sys.stdin) # pylint: disable=invalid-name
sys.exit(_xit)
#####