forked from cmu-vision/cmu-vision.github.io
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gen_people_page.py
108 lines (88 loc) · 3.77 KB
/
gen_people_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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
import os
import glob
import random
def read_file(fpath):
with open(fpath, 'r') as f:
content = f.read()
return content
def get_txtfile_ids(folder):
txtfiles = glob.glob('{}/*.txt'.format(folder))
ids = [os.path.basename(txtfile)[:-4] for txtfile in txtfiles]
return ids
# <img class="paper static" title="paper" src="src.png" />
def parse_person_info(person_id, person_folder):
elems = {}
keys = []
fpath = os.path.join(person_folder, person_id + '.txt')
with open(fpath, 'r') as f:
for ln in f.readlines():
ln_items = ln.split('::')
if len(ln_items) != 2:
continue
key, val = ln_items[0], ln_items[1]
key = key.rstrip().lstrip()
val = val.rstrip().lstrip()
elems[key] = val
keys.append(key)
if 'url' not in keys:
elems['url'] = '#'
if 'img' not in keys:
elems['img'] = 'assets/incognito.jpeg'
return elems, keys
def get_person_html_string(id, elems, keys):
comment_str = '<!--------------------------------------------------------------------------->'
person_str = ''
person_str += '\n' + comment_str + '\n'
person_str += '<table class="personTable" id="{}">\n'.format(id)
person_str += '<tr>\n<td>\n'
person_str += '<a href="{}">\n <div class="imButtonWrapper"> \n <img alt="{}" src="{}" />\n</div>\n</a>\n'.format(elems['url'], elems['name'], elems['img'])
person_str += '</td>\n</tr>\n<tr>\n<td>\n'
person_str += '<a href="{}">{}</a>\n'.format(elems['url'], elems['name'])
person_str += '</td>\n</tr>\n</table>\n'
## Meta fields
# add some javascript here if needed using the id for the added element
person_str += comment_str + '\n'
return person_str
if __name__ == '__main__':
page_string = read_file('./people_base.html')
###########################################################################
###########################################################################
folder = './people/faculty'
people_string = ''
ids = get_txtfile_ids(folder)
random.shuffle(ids)
for id in ids:
elems, keys = parse_person_info(id, folder)
people_string += get_person_html_string(id, elems, keys)
page_string = page_string.replace('<!-- autogen faculty -->', '<!-- autogen faculty -->\n' + people_string)
###########################################################################
###########################################################################
folder = './people/postdocs'
people_string = ''
ids = get_txtfile_ids(folder)
random.shuffle(ids)
for id in ids:
elems, keys = parse_person_info(id, folder)
if 'year' not in keys:
continue
people_string += get_person_html_string(id, elems, keys)
page_string = page_string.replace('<!-- autogen postdocs -->', '<!-- autogen postdocs -->\n' + people_string)
###########################################################################
###########################################################################
folder = './people/students'
people_string = ''
ids = get_txtfile_ids(folder)
random.shuffle(ids)
for id in ids:
elems, keys = parse_person_info(id, folder)
if 'year' not in keys:
continue
if 'program' not in keys:
continue
people_string += get_person_html_string(id, elems, keys)
page_string = page_string.replace('<!-- autogen students -->', '<!-- autogen students -->\n' + people_string)
###########################################################################
###########################################################################
fpath = './index.html'
with open(fpath, 'w') as f:
f.write(page_string)