Skip to content

Commit 0e99a4c

Browse files
committed
Update script formatting
1 parent 5a0a8d4 commit 0e99a4c

File tree

7 files changed

+56
-29
lines changed

7 files changed

+56
-29
lines changed

src/scripts/initial/defs_converter.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import os
22
import re
33

4+
45
def update_question_file(file_path):
56
with open(file_path, "r", encoding="utf-8") as f:
67
lines = f.readlines()
@@ -23,16 +24,18 @@ def update_question_file(file_path):
2324
with open(file_path, "w", encoding="utf-8") as f:
2425
f.writelines(updated_lines)
2526

27+
2628
def find_and_update_question_files(directory):
2729
for root, _, files in os.walk(directory):
2830
for file in files:
2931
if file == "question.ts":
3032
question_file_path = os.path.join(root, file)
3133
update_question_file(question_file_path)
3234

35+
3336
if __name__ == "__main__":
3437
# Define the specific directory path here
3538
directory = r"C:\Users\johnl\OneDrive\Documents\GitHub\questions\src\content\questions\comp2804"
3639
find_and_update_question_files(directory)
37-
40+
3841
print("question.ts files have been updated.")

src/scripts/initial/file finder programs/empty_solution_file_finder.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import os
22

3+
34
def find_empty_solution_files(directory):
45
for root, _, files in os.walk(directory):
56
for file in files:
@@ -11,6 +12,7 @@ def find_empty_solution_files(directory):
1112
if not content:
1213
print(f"Empty file: {relative_path}")
1314

15+
1416
if __name__ == "__main__":
1517
# Define the specific directory path here
1618
directory = r"C:\Users\johnl\OneDrive\Documents\GitHub\questions\src\content\questions\comp2804"

src/scripts/initial/file finder programs/no_solution_for_index.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,23 @@
11
import os
22

3+
34
def find_empty_solution_files(directory):
45
for root, _, files in os.walk(directory):
56
if "solution.md" in files and "index.md" in files:
67
solution_file_path = os.path.join(root, "solution.md")
78
index_file_path = os.path.join(root, "index.md")
8-
9-
with open(solution_file_path, "r", encoding="utf-8") as sf, open(index_file_path, "r", encoding="utf-8") as inf:
9+
10+
with open(solution_file_path, "r", encoding="utf-8") as sf, open(
11+
index_file_path, "r", encoding="utf-8"
12+
) as inf:
1013
solution_content = sf.read().strip()
1114
index_content = inf.read()
1215

1316
if not solution_content and "solution" in index_content:
1417
relative_index_path = os.path.relpath(index_file_path, directory)
1518
print(f"Index file: {relative_index_path}")
1619

20+
1721
if __name__ == "__main__":
1822
# Define the specific directory path here
1923
directory = r"C:\Users\johnl\OneDrive\Documents\GitHub\questions\src\content\questions\comp2804"

src/scripts/initial/file finder programs/warning_finder.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import os
22

3+
34
def find_solution_files_with_warning(directory):
45
for root, _, files in os.walk(directory):
56
for file in files:
@@ -11,6 +12,7 @@ def find_solution_files_with_warning(directory):
1112
if "warning" in content.lower():
1213
print(f"'Warning' found in file: {relative_path}")
1314

15+
1416
if __name__ == "__main__":
1517
# Define the specific directory path here
1618
directory = r"C:\Users\johnl\OneDrive\Documents\GitHub\questions\src\content\questions\comp2804"
Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,60 +1,65 @@
11
import os
22
import re
33

4+
45
def find_unique_tags(directory):
56
unique_tags = set()
6-
tag_pattern = re.compile(r'tags:\s*\n((?:\s*-\s*[^\n]+\n)*)', re.IGNORECASE)
7+
tag_pattern = re.compile(r"tags:\s*\n((?:\s*-\s*[^\n]+\n)*)", re.IGNORECASE)
78

89
for root, _, files in os.walk(directory):
910
if "index.md" in files:
1011
index_file_path = os.path.join(root, "index.md")
11-
12+
1213
with open(index_file_path, "r", encoding="utf-8") as inf:
1314
index_content = inf.read()
1415
tag_match = tag_pattern.search(index_content)
15-
16+
1617
if tag_match:
1718
tags_block = tag_match.group(1)
18-
tags = re.findall(r'-\s*([^\n]+)', tags_block)
19+
tags = re.findall(r"-\s*([^\n]+)", tags_block)
1920
unique_tags.update(tags)
20-
21+
2122
return unique_tags
2223

24+
2325
def parse_tag(tag):
24-
match = re.search(r'\(([\d.]+)\)$', tag)
26+
match = re.search(r"\(([\d.]+)\)$", tag)
2527
if match:
26-
numbers = tuple(map(int, match.group(1).split('.')))
28+
numbers = tuple(map(int, match.group(1).split(".")))
2729
else:
2830
numbers = ()
2931
return numbers
3032

33+
3134
def sort_tags(tags):
3235
return sorted(tags, key=lambda tag: (parse_tag(tag), tag))
3336

37+
3438
def create_display_tags(tags):
3539
display_tags = {}
3640
for tag in tags:
3741
key = "comp2804-" + tag.lower().replace(" ", "-")
3842
display_tags[key] = tag
3943
return display_tags
4044

45+
4146
if __name__ == "__main__":
4247
# Define the specific directory path here
4348
directory = r"C:\Users\johnl\OneDrive\Documents\GitHub\questions\src\content\questions\comp2804"
4449
unique_tags = find_unique_tags(directory)
45-
50+
4651
# Sort the tags with the custom sorting function
4752
sorted_tags = sort_tags(unique_tags)
48-
53+
4954
# Create display tags
5055
display_tags = create_display_tags(sorted_tags)
51-
56+
5257
# Write display tags to a file
5358
output_path = os.path.join(directory, "displayTags.js")
5459
with open(output_path, "w", encoding="utf-8") as f:
5560
f.write("const displayTags = {\n")
5661
for key, display in display_tags.items():
5762
f.write(f' "{key}": "{display}",\n')
5863
f.write("};\n")
59-
64+
6065
print(f"Display tags have been written to {output_path}")

src/scripts/initial/tag_checker.py

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,48 @@
11
import os
22
import re
33

4+
45
def find_unique_tags(directory):
56
unique_tags = set()
6-
tag_pattern = re.compile(r'tags:\s*\n((?:\s*-\s*[^\n]+\n)*)', re.IGNORECASE)
7+
tag_pattern = re.compile(r"tags:\s*\n((?:\s*-\s*[^\n]+\n)*)", re.IGNORECASE)
78

89
for root, _, files in os.walk(directory):
910
if "index.md" in files:
1011
index_file_path = os.path.join(root, "index.md")
11-
12+
1213
with open(index_file_path, "r", encoding="utf-8") as inf:
1314
index_content = inf.read()
1415
tag_match = tag_pattern.search(index_content)
15-
16+
1617
if tag_match:
1718
tags_block = tag_match.group(1)
18-
tags = re.findall(r'-\s*([^\n]+)', tags_block)
19+
tags = re.findall(r"-\s*([^\n]+)", tags_block)
1920
unique_tags.update(tags)
20-
21+
2122
return unique_tags
2223

24+
2325
def parse_tag(tag):
24-
match = re.search(r'\(([\d.]+)\)$', tag)
26+
match = re.search(r"\(([\d.]+)\)$", tag)
2527
if match:
26-
numbers = tuple(map(int, match.group(1).split('.')))
28+
numbers = tuple(map(int, match.group(1).split(".")))
2729
else:
2830
numbers = ()
2931
return numbers
3032

33+
3134
def sort_tags(tags):
3235
return sorted(tags, key=lambda tag: (parse_tag(tag), tag))
3336

37+
3438
if __name__ == "__main__":
3539
# Define the specific directory path here
3640
directory = r"C:\Users\johnl\OneDrive\Documents\GitHub\questions\src\content\questions\comp2804"
3741
unique_tags = find_unique_tags(directory)
38-
42+
3943
# Sort the tags with the custom sorting function
4044
sorted_tags = sort_tags(unique_tags)
41-
45+
4246
# Print the sorted unique tags
4347
for tag in sorted_tags:
4448
print(tag)
Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,46 @@
11
import os
22
import re
33

4+
45
def update_tags_in_file(file_path):
56
with open(file_path, "r", encoding="utf-8") as f:
67
content = f.read()
78

8-
tags_pattern = re.compile(r'(tags:\s*\n)((?:\s*-\s*[^\n]+\n)*)', re.IGNORECASE)
9+
tags_pattern = re.compile(r"(tags:\s*\n)((?:\s*-\s*[^\n]+\n)*)", re.IGNORECASE)
910
match = tags_pattern.search(content)
1011

1112
if match:
1213
tags_block = match.group(2)
13-
tags = re.findall(r'-\s*([^\n]+)', tags_block)
14+
tags = re.findall(r"-\s*([^\n]+)", tags_block)
1415
updated_tags = []
1516

1617
for tag in tags:
1718
if not tag.startswith("comp2804"):
1819
tag = "comp2804 " + tag
1920
updated_tag = tag.lower().replace(" ", "-")
2021
updated_tags.append(updated_tag)
21-
22-
updated_tags_block = "tags:\n" + "\n".join([f" - {tag}" for tag in updated_tags]) + "\n"
23-
updated_content = content[:match.start(2)] + updated_tags_block + content[match.end(2):]
22+
23+
updated_tags_block = (
24+
"tags:\n" + "\n".join([f" - {tag}" for tag in updated_tags]) + "\n"
25+
)
26+
updated_content = (
27+
content[: match.start(2)] + updated_tags_block + content[match.end(2) :]
28+
)
2429

2530
with open(file_path, "w", encoding="utf-8") as f:
2631
f.write(updated_content)
2732

33+
2834
def find_and_update_tags(directory):
2935
for root, _, files in os.walk(directory):
3036
if "index.md" in files:
3137
index_file_path = os.path.join(root, "index.md")
3238
update_tags_in_file(index_file_path)
3339

40+
3441
if __name__ == "__main__":
3542
# Define the specific directory path here
3643
directory = r"C:\Users\johnl\OneDrive\Documents\GitHub\questions\src\content\questions\comp2804"
3744
find_and_update_tags(directory)
38-
45+
3946
print("Tags have been updated in all index.md files.")

0 commit comments

Comments
 (0)