-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathgather_notes.py
More file actions
executable file
·50 lines (37 loc) · 1.06 KB
/
gather_notes.py
File metadata and controls
executable file
·50 lines (37 loc) · 1.06 KB
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
#!/usr/bin/env python3
import sys
from collections import OrderedDict
text = sys.stdin.read().splitlines()
versions: OrderedDict[str, list[str]] = OrderedDict()
current = None
buffer: list[str] = []
def flush_buffer():
if buffer and current:
item = '\n'.join(buffer).rstrip()
if item.strip().lower() in ('* no changes'):
buffer.clear()
return
if item not in versions[current]:
versions[current].append(item)
buffer.clear()
for line in text:
line = line.rstrip()
if not line.strip():
continue
if line.endswith(':'): # version header
flush_buffer()
current = line[:-1].strip()
versions.setdefault(current, [])
continue
if current is None:
continue
if line.lstrip().startswith('*'): # start of new bullet
flush_buffer()
buffer.append(line)
flush_buffer()
for i, (version, items) in enumerate(versions.items()):
print(f'{version}:')
for item in items:
print(item)
if i < len(versions) - 1:
print()