-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathextract
executable file
·74 lines (63 loc) · 2.03 KB
/
extract
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
#!/usr/bin/env python3
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at https://mozilla.org/MPL/2.0/.
# Author: Manuel Bucher <[email protected]>
# Date: 2024-01-23
import sys
import re
import datetime
# <p><strong>[2024-01-09] 2024 Edition! </strong></p></td>
def main():
try:
_, inp = sys.argv
except:
print(f"usage: {sys.argv[0]} INPUT.md")
return
date = ""
extract = False
last_out = ""
out = {}
for line in open(inp):
public = '--- public ---' in line
private = '--- private ---' in line
if not extract:
if public and private:
continue
if public:
extract = True
continue
if private:
print("non-matching private tag")
return 1
# look for next section
if '[' in line:
new_date = line.split('[', 1)[1]
new_date = new_date.split(']', 1)[0]
try:
new_date = datetime.datetime.strptime(new_date, '%Y-%m-%d')
except ValueError:
continue
date = new_date.strftime("%Y-%m-%d")
last_out = last_out.strip()
if last_out != "":
out[date] = last_out + "\n"
last_out = ""
print(date)
else:
if public and private:
print("public and private tag in public section")
return 1
elif public:
print("public tag in public section")
return 1
elif private:
extract = False
else:
last_out += line
# write all meeting notes to files
for day in out:
with open(f"archive/meeting-{day}.md", "w") as f:
f.write(out[day])
if __name__ == '__main__':
sys.exit(main())