-
Notifications
You must be signed in to change notification settings - Fork 0
/
patch_readme_homepage.py
78 lines (63 loc) · 2.05 KB
/
patch_readme_homepage.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
from functions import *
from modules_info import *
import re
files_obj_dict = {
"homepage": fileAsStrHandler(node_home_path),
"readme": fileAsStrHandler(readme_path),
}
# REPLACEMENTS BETWEEN TWO SPECIFIC STRINGS:
fifths_for_replace_between = [
# [begin_of_string,end_of_string,new_middle,file_as_string,consider linebreaks (generally False)]
["https://", ".github.io", USERNAME, files_obj_dict["homepage"], False],
["<CITYNAME>", "<CITYNAME>", CITY_NAME, files_obj_dict["readme"], False],
[
"<!--CITYNAME INSERTION-->",
"<!--CITYNAME INSERTION-->",
CITY_NAME,
files_obj_dict["homepage"],
False,
],
[
".github.io/",
"/data/data_updating.html",
REPO_NAME,
files_obj_dict["homepage"],
False,
],
[
"<!--MODULES INSERTION POINT-->",
"<!--MODULES INSERTION POINT-->",
modules_as_str,
files_obj_dict["homepage"],
True,
],
]
# print(find_between_strings(readme_as_str,'<CITYNAME>','<CITYNAME>'))
for i, fifth in enumerate(fifths_for_replace_between):
# firstly, finding matches:
for match in find_between_strings(
fifth[3].content,
fifth[0],
fifth[1],
exclusions=["buttons"],
include_linebreaks=fifth[4],
):
if len(match) < 100:
print(i, "replacing between", fifth[0], fifth[1], "match: ", match)
original_str = f"{fifth[0]}{match}{fifth[1]}"
new_str = f"{fifth[0]}{fifth[2]}{fifth[1]}"
fifth[3].simple_replace(original_str, new_str)
triads_for_simple_replacements = [
# always: [ORIGINAL STRING, NEW STRING, FILE OBJ]
[
"https://opensidewalkmap.github.io/oswm_codebase/",
"https://kauevestena.github.io/oswm_codebase/",
files_obj_dict["homepage"],
], # doing the ugly way, temporarily
]
for triad in triads_for_simple_replacements:
triad[2].simple_replace(triad[0], triad[1])
# print(readme_as_str)
# commiting changes:
for entry in files_obj_dict:
files_obj_dict[entry].rewrite()