-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.py
More file actions
61 lines (47 loc) · 2.4 KB
/
main.py
File metadata and controls
61 lines (47 loc) · 2.4 KB
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
from identify_article_features import *
from update_links import *
import os
from tqdm import tqdm
wiki_directory = "../Proof-Tree.wiki/"
def main():
# clear the roots page
print("clearing roots article")
with open(wiki_directory + "Roots.md") as roots_article:
content = roots_article.read()
content = content[:content.index("## Root Articles") + 16]
with open(wiki_directory + "Roots.md", "w") as roots_article:
roots_article.write(content)
# clear the missing articles page
print("clearing missing articles")
with open(wiki_directory + "Missing-Articles.md") as missing_article:
content = missing_article.read()
content = content[:content.index('## List of Missing Articles') + 27]
with open(wiki_directory + "Missing-Articles.md", 'w') as missing_article:
missing_article.write(content)
# clear the incomplete-articles page
with open(wiki_directory + "Incomplete-Articles.md") as incomplete_article:
content = incomplete_article.read()
content = content[:content.index(":") + 1]
with open(wiki_directory + "Incomplete-Articles.md", 'w') as incomplete_article:
incomplete_article.write(content)
# loop over all files in directory
print("updating links")
for file in tqdm(os.listdir(wiki_directory), desc="Updating Links"):
# get filename
article_name = os.fsdecode(file)
# only need to update links on markdown files that are article files
if article_name.endswith('.md') and article_name not in IGNORE_LIST:
with open(wiki_directory + article_name) as article:
article_content = article.read()
article_sections = get_sections(article_content)
update_article_links(article_name, article_sections)
# if this article is a root then add it to the roots article
if is_root(article_sections):
with open(wiki_directory + "Roots.md", "a") as roots_article:
roots_article.write('\n- ' + name_to_link(article_name))
# if this article is missing a source then add it to the incomplete articles list
if is_missing_sources(article_sections):
with open(wiki_directory + "Incomplete-Articles.md", "a") as incomplete_article:
incomplete_article.write("\n- " + name_to_link(article_name))
if __name__ == "__main__":
main()