-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild_studentlist.py
191 lines (151 loc) · 3.6 KB
/
build_studentlist.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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
import pandas as pd
import os
import os.path as osp
head = u"""
+++
date = "2010-01-01T12:00:00"
draft = false
tags = ["events","tum"]
title = "MSNE Students"
menu = "main"
math = true
+++
<style>
.card {
box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.4);
width:50%;
height: 350px;
max-width:200px;
margin: 10px 5px;
text-align: center;
background-color: #f5f5f5;
padding: 5px 5px 5px 5px;
float: left;
}
card.col1 {
float: left;
width: 20%;
}
card.col2 {
float: left;
width: 70%;
}
card.title {
font-size: 100pt;
}
a.link {
text-decoration: none;
font-size: 18px;
}
.image-cropper {
width: 100px;
height: 100px;
margin: 10px auto;
position: relative;
overflow: hidden;
border-radius: 50%;
}
img {
display: inline;
margin-left: auto;
margin-right: auto;
height: 100%;
width: 100%;
margin: 0 auto;.
align: center;
}
.linklist {
height:100%;
}
</style>
"""
tmpl = u"""
<div class="card">
<div class="image-cropper">
<img src="{file}" >
</div>
<p><b>{first} {last}</b>
</br>
{text}
</p>
<div id="linklist">
{links}
</div>
</div>
"""
linktypes = [ 'envelope',
'link',
'linkedin',
'github',
'twitter',
'facebook',
'scholar']
root = 'static/img/student-list'
pageroot = '/img/student-list'
files = [osp.join(pageroot, f) for f in os.listdir(root)]
df = pd.read_csv('student-listing.csv')
names = ['{}'.format(j) for i,j in df[['First Name', 'Last Name']].values]
def normalize(s):
return s.lower().replace('í', 'i')
def match(names, files):
m = []
for n in names:
for f in files:
if normalize(n) in normalize(f):
m.append(f)
break
else:
print('Missing {}'.format(n))
m.append(None)
return m
df['File'] = match(names, files)
df['E-Mail'] = 'mailto:' + df['E-Mail']
df['first'] = df['First Name']
remap = {
'First Name' : 'first',
'Last Name' : 'last',
'Description' : 'text',
'E-Mail' : 'envelope',
'LinkedIn Profile URL' : 'linkedin',
'Github Profile URL' : 'github',
'Twitter Profile URL' : 'twitter',
'Facebook Profile URL' : 'facebook',
'Google Scholar URL' : 'scholar',
'Website URL' : 'link',
'File' : 'file'
}
fillna = {
'First Name' : '',
'Last Name' : '',
'Description' : '',
'E-Mail' : '#',
'LinkedIn Profile URL' : '#',
'Github Profile URL' : '#',
'Twitter Profile URL' : '#',
'Facebook Profile URL' : '#',
'Google Scholar URL' : '#',
'Website URL' : '#',
'Profile Picture' : 'placeholder.png'
}
tgt = pd.DataFrame()
df = df.fillna(value=fillna)
for k, v in remap.items():
tgt[v] = df[k]
tgt = tgt.sort_values('last').reset_index(drop=True)
from math import isnan
html = head
link_tmpl = u"""<a href="{value}" class="link"><i class="fa fa-{key}"></i></a>"""
for i in range(len(df)):
my_dict = tgt.loc[i].to_dict()
d = {k: my_dict[k] for k in my_dict if not str(my_dict[k]) == '#'}
#print(d)
links = []
for l in linktypes:
if l in d:
links.append(link_tmpl.format(key = l, value=d[l]))
del(d[l])
d['links'] = '\n'.join(links)
html += tmpl.format(**d)
from IPython.core.display import HTML
with open('content/post/static.md', 'w') as fp:
fp.write(html)