-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreplace_text_from_posts.py
executable file
·54 lines (40 loc) · 1.7 KB
/
replace_text_from_posts.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
import re
import argparse
import os
def parse_arguments()->argparse.Namespace:
parser = argparse.ArgumentParser(description="Replace [[ and ]] with ` and netcat|nc with netcat")
parser.add_argument("file", help="Input file to process")
return parser.parse_args()
def process_content(content: str):
"""
Replace content from Obsidian notes to Hugo format
"""
# Replace "[[" and "]]" with "`"
content = re.sub(r'\[\[', '`', content)
content = re.sub(r'\]\]', '`', content)
# Replace some tags from Obsidian
content = re.sub(r'netcat\|nc', 'netcat', content)
content = re.sub(r'CrackMapExec\|NetExec', 'NetExec', content)
content = re.sub(r'Server Message Block\|SMB', 'SMB', content)
content = re.sub(r'Simple Mail Transfer Protocol\|SMTP', 'SMTP', content)
content = re.sub(r'Windows Remote Management\|WinRM', 'WinRM', content)
content = re.sub(r'Lightweight Directory Access Protocol\|LDAP', 'LDAP', content)
content = re.sub(r'Microsoft SQL Server\|MSSQL', 'MSSQL', content)
return content
def process_file(file_path: str):
if not os.path.isfile(file_path):
print("Error: Input file not found.")
return None
# Read the content of the input file
with open(file_path, 'r') as f:
content = f.read()
modified_content = process_content(content)
# Write the modified content back to the file
with open(file_path, 'w') as f:
f.write(modified_content)
return file_path
if __name__ == "__main__":
args: argparse.Namespace = parse_arguments()
processed_file = process_file(args.file)
if processed_file:
print("Replacement completed successfully for", processed_file)