make sure to include Twitter links in recap
[Ultimately_Untrue_Thought.git] / notes / patriate_links.py
1 #!/usr/bin/python3
2
3 import re
4 import sys
5
6 # Python script to rewrite Markdown links and remove anchors
7 # mostly by GPT-4
8
9 # Define the path for the input and output files
10 input_file_path = sys.argv[1]
11 output_file_path = "out.md"
12
13 # Define the regular expression patterns for Markdown links and anchors
14 relative_link_pattern = re.compile(r'\]\(/(\d{4}/\w{3}/[-\w]+/)(#[-\w]+)?\)')
15 relative_image_link_pattern = re.compile(r'\]\((/images/[-\w./]+)\)')
16 anchor_pattern = re.compile(r'<a id="[-\w]+"></a>')
17
18 # TODO: don't neglect images
19
20 # Read the content of the original markdown file
21 with open(input_file_path, 'r') as file:
22     content = file.read()
23
24 # Replace the Markdown links with the new format
25 rewritten_content = relative_link_pattern.sub(r'](http://unremediatedgender.space/\1)', content)
26 rewritten_content = relative_image_link_pattern.sub(r'](http://unremediatedgender.space/\1)', rewritten_content)
27
28 # Remove the anchors
29 rewritten_content = anchor_pattern.sub('', rewritten_content)
30
31 # Write the rewritten content to a new file
32 with open(output_file_path, 'w') as file:
33     file.write(rewritten_content)
34
35 print(f"rewritten markdown has been saved to {output_file_path}")