File: replace_words.py

package info (click to toggle)
python-inline-snapshot 0.23.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,116 kB
  • sloc: python: 6,888; makefile: 34; sh: 28
file content (24 lines) | stat: -rw-r--r-- 595 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import re
import sys


def replace_words(file_path, replacements):
    with open(file_path) as file:
        content = file.read()

    for old_word, new_word in replacements.items():
        content = re.sub(rf"\b{re.escape(old_word)}\b", new_word, content)

    with open(file_path, "w") as file:
        file.write(content)


if __name__ == "__main__":

    replacements = {
        "http://localhost:8000/inline-snapshot/": "https://15r10nk.github.io/inline-snapshot/latest/",
    }

    for file_path in sys.argv[1:]:
        print(file_path)
        replace_words(file_path, replacements)