-
Notifications
You must be signed in to change notification settings - Fork 1
/
make_member_page.py
executable file
·87 lines (84 loc) · 3.63 KB
/
make_member_page.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
import os
with open("members/index.md", "w") as outf:
outf.write("---\nlayout: default\n---\n# Cersonsky Lab Members\n")
n = 0
subtitle = ""
peeps = []
peepcodes = []
for line in open("members.txt"):
if line in [
"principal investigator\n",
"postdoctoral researchers\n",
"graduate researchers\n",
"undergraduate researchers\n",
"visitors and collaborators\n",
"alumni\n",
]:
if n > 0:
skip = n
if n >= 3:
s = '\n\n<h2 style="text-align: center;"> {}</h2>\n\n| | | |\n|:----:|:----:|:----:|\n'.format(
subtitle.title()
)
skip = 3
elif n == 2:
s = '\n\n<h2 style="text-align: center;"> {}</h2>\n\n| | |\n|:----:|:----:|\n'.format(
subtitle.title()
)
else:
s = '\n\n<h2 style="text-align: center;"> {}</h2>\n\n| |\n|:----:|\n'.format(
subtitle.title()
)
outf.write(s)
for i in range(len(peeps))[::skip]:
my_peeps = peeps[i : i + skip]
my_peepcodes = peepcodes[i : i + 3]
images = ""
names = ""
for j in range(skip):
if j < len(my_peeps):
ext = "png"
if not os.path.exists(
"assets/img/{}.png".format(my_peepcodes[j])
):
if not os.path.exists(
"assets/img/{}.jpg".format(my_peepcodes[j])
):
raise FileNotFoundError(
"File assets/img/{}.png does not exist.".format(
my_peepcodes[j]
)
)
else:
ext = "jpg"
if not os.path.exists(
"./members/{}.md".format(my_peepcodes[j])
):
raise FileNotFoundError(
"./members/{}.md does not exist.".format(
my_peepcodes[j]
)
)
images += "|<a href='/website/members/{}'><img src='/website/assets/img/{}.{}' style='max-height:200px'></a>".format(
my_peepcodes[j], my_peepcodes[j], ext
)
names += '|<a href="/website/members/{}">{}</a>'.format(
my_peepcodes[j], my_peeps[j]
)
else:
images += "| "
names += "| "
images += "|\n"
names += "|\n"
outf.write(images)
outf.write(names)
outf.write("{:.custom-table}\n\n------\n")
n = 0
subtitle = line
peeps = []
peepcodes = []
elif line != "\n":
line = line.strip("\n").strip(" - ")
peeps.append(line)
peepcodes.append(line.lower().replace(" ", "_"))
n += 1