-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathremove_times.py
42 lines (33 loc) · 1.17 KB
/
remove_times.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
import re
def remove_timespans(text):
"""
Remove timespans from the given text and format it into a specific structure.
Args:
text (str): The input text containing timespans and tasks.
Returns:
str: The formatted text with timespans removed and tasks organized.
"""
pattern = r"\b\d{1,2}(:\d{1,2})?-\d{1,2}(:\d{1,2})?\b,? *"
result = re.sub(pattern, "", text)
lines = result.split('\n')
BOLD = "\033[1m"
UNDERLINE = "\033[4m"
END = "\033[0m"
day_tasks = []
output = []
for line in lines:
is_day_line = re.match(r'^\s*•\s*(\w+day)', line)
if is_day_line:
if day_tasks:
output.append('\n'.join(day_tasks) + '\n')
day_tasks = []
day = re.sub(r'^\s*•\s*(\w+day)', r'\1', line)
day = re.sub(r'(\w+day)', BOLD + UNDERLINE + r'\1' + END, day)
day_tasks.append(day)
else:
task = re.sub(r'^\s*o\s*', '\t• ', line)
day_tasks.append(task)
if day_tasks:
output.append('\n'.join(day_tasks) + '\n')
result = '\n'.join(output)
return result