-
Notifications
You must be signed in to change notification settings - Fork 0
/
TOC.py
163 lines (125 loc) · 4.26 KB
/
TOC.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
#!/usr/local/bin/python3
# File to generate the SUMMARY.md file for the gitbook
# - filter for gitignore
# - filter for system files
# - filter for images/ directories
#%%
import os
#%%
semesters = {
"vwl1": "I. Semester",
"vwl2": "II. Semester",
"vwl3": "III. Semester",
"vwl4": "IV. Semester",
"vwl5": "V. Semester",
"vwl6": "VI. Semester",
}
dir_names = {
"VL_Buchfuehrung": "Buchführung",
"VL_BWL": "BWL",
"VL_Mathe1": "Mathe",
"VL_VWL": "VWL ",
"VL_Statistik1": "Statistik ",
"VL_Wirtschaftsinformatik": "Wirtschaftsinfo",
"VL_Mathe2": "Mathematik II",
"VL_Statistik2": "Statistik II",
"VL_Mikro": "Mikroökonomik",
"VL_WissArbeit": "Wissenschaftliches Arbeiten",
"VL_Recht-WiWi": "Recht für WiWi",
"VL_Stadt": "Stadtökonomie (Leipzig)",
"VL_Ethik": "Ethik der Soz. Marktwirtschaft",
"VL_Makro1": "Makroökonomik I",
"VL_Mikro2": "Mikroökonomik II",
"VL_Monetaer": "Monetäre Ökonomik",
"VL_Wachstum": "Wachstum und Nachhaltigkeit",
"VL_Soziologie": "Wirtschaftssoziologie",
"VL_Angewandte": "Angewandte Ökonomik",
"VL_Makro2": "Makroökonomik II",
"VL_International": "International Economics",
"VL_SoEco": "Sozial-Ökologische Systeme",
"VL_WiPo": "Wirtschaftspolitik",
"VL_EconHistory": "Economic History",
"VL_Empirical": "Empirical Economics",
"VL_Feminist": "Feminist Economics",
"VL_PublicEcon": "Public Economics",
"VL_Zivilrecht": "Zivilrecht",
"VL_Econometrics": "Econometrics",
"VL_Umwelt": "Umweltökonomie",
"VL_Sozialismus": "Sozialismus",
"VL_Macrometrics": "Macroeconometrics"
}
#%%
with open(".gitignore") as f:
ignores = f.read().splitlines()
ignores.append([
"SUMMARY.md",
"TOC.py",
"README.md",
"images",
"LICENSE.md",
])
#%%
# get all files in the directory and subdirectories with type {dirname : filenames}
result_list = ["root: index", "subtrees:"] # first two lines of the SUMMARY.md
result_list.append(f"""
- caption: "Inhaltsverzeichnis"
hidden: True
maxdepth: 1
titlesonly: True
entries:
""")
# Add the files in /glossar
result_list.append(f"""
- file: glossar/Allgemein
title: "Glossar"
entries:
""")
## Add the files in /glossar
for file in sorted(os.listdir("glossar")):
if file[-3:] == ".md" and file != "Allgemein.md":
filename = file[:-3]
filename = filename.replace("_", " ")
filename = filename.replace("-", " ")
result_list.append(f"""
- file: glossar/{file}
title: "{filename}"
""")
#%%
# count the files and directories
count_files = 0
count_dirs = 0
for semester, desc in semesters.items():
# add the semester as a headline
result_list.append(f"""
- file: {semester}/README
title: {desc}
entries:
""")
for dir in os.listdir(semester):
if dir in dir_names.keys():
# add the directory name as a headline
result_list.append(f" - file: {semester}/{dir}/README")
result_list.append(f" title: {dir_names[dir]}")
result_list.append(f" entries:")
count_dirs += 1 # count the directories
for file in sorted(os.listdir(f"{semester}/{dir}")):
# ignore README
if file == "README.md":
# dont add the README to the list
pass
elif file not in ignores:
if file[-3:] == ".md": # only add markdown files, not directories
filename = file[11:-3]
filename = filename.replace("_", " ")
filename = filename.replace("-", " ")
# add the file to the list
result_list.append(f" - file: {semester}/{dir}/{file}")
result_list.append(f" title: {filename}")
count_files += 1 # count the files
# add the number of files and directories to the end of the SUMMARY.md
#result_list.append(f"**{count_files}** Notizen in **{count_dirs}** Modulen")
print(f"**{count_files}** Notizen in **{count_dirs}** Modulen")
with open("_toc.yml", "w") as f:
f.writelines(line + '\n' for line in result_list)
print("TOC updated")
# %%