-
Notifications
You must be signed in to change notification settings - Fork 0
/
parse.py
64 lines (45 loc) · 1.34 KB
/
parse.py
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
import re
lines = [
'---',
'up:',
' - "[[Efforts]]"',
'related:'
' - "[[Academic Efforts]]"',
'created: 2023-02-01',
'aceWhoInst:',
' - Yale',
'aceWhoTeam:',
' - Alex',
' - "[[Biniam Garomsa]]"',
'aceLinksCode:',
' - https://github.com/alexjakubow/lgll-student-survey',
'aceLinksData:',
' - https://osf.io/rbya9/',
'aceSummary: Assist with the implementation and analysis of the annual student survey of library services.',
'aceStatus: In progress',
'databytes: true',
'aceUpdate: Codebase revised and working on next iteration of the dashboard',
'updated: 2024-10-25',
'---'
]
text = '\n'.join(lines)
def is_property_line(x):
re.search("^---$", x)
def extract_properties(file_path):
"""Returns properties header from an Obsidian note"""
with open(file_path, 'r') as file:
text = file.readlines()
def extract_key_value_pairs(file_path):
"""Extracts key-value pairs from a text file with multiline values."""
with open(file_path, 'r') as file:
text = file.read()
pairs = {}
matches = re.findall(r'(\w+):\s*([\s\S]*?)(?=\w+:|$)', text)
for key, value in matches:
pairs[key] = value.strip()
return pairs
print(text)
# if __name__ == '__main__':
# file_path = 'your_text_file.txt' # Replace with your file path
# result = extract_key_value_pairs(file_path)
# print(result)