-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrender.py
More file actions
70 lines (62 loc) · 2.73 KB
/
render.py
File metadata and controls
70 lines (62 loc) · 2.73 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
62
63
64
65
66
67
68
69
70
import argparse
import bibtexparser # pip install --no-cache-dir --force-reinstall git+https://github.com/sciunto-org/python-bibtexparser@main
_PAPER_TEMPLATE = '''
<div id="main-pub-card-container" class="activated hide">
<div class="pub-card" data-topic="{topics}" data-year="{year}" data-selected="{selected}">
<div class="row">
<div class="col-r col-xs-12 col-12">
<div class="pub-card-body">
<h5 class="title">{title}</h5>
<h6 class="authors">
<u>{authors}</u>
</h6>
<p class="info">
{site}
<a href="{link}"
target="_blank">Paper</a><br>
<span class="highlight">{note}</span>
</p>
</div>
</div>
</div>
</div>
</div>
'''
def process_authors(authors: str) -> str:
authors = authors.split(' and ')
authors = map(lambda x: reversed([y.strip() for y in x.strip().split(',')]), authors)
authors = map(lambda x: ' '.join(x), authors)
return ', '.join(authors)
if __name__ == '__main__':
with open('data/grounding.bib') as f:
library = bibtexparser.parse_string(f.read())
entries = list()
for item in library.entries:
year = item['year']
authors = process_authors(item['author'])
topics = [x.strip() for x in item['keywords'].split(',')]
selected = True if 'selected' in topics else False
title = item['title']
link = '#' if 'url' not in item else item['url']
note = item['note'] if 'note' in item else ''
if item.entry_type == 'phdthesis':
site = f'PhD Thesis, {item["school"]}'
else:
site = item['journal'] if 'journal' in item else item['booktitle']
site += f' {item["year"]}'
entry = _PAPER_TEMPLATE.format(
topics=','.join(topics),
year=year,
selected='true' if selected else 'false',
title=title,
authors=authors,
site=site,
link=link,
note=note
)
entries.append(entry)
with open('index_template.html') as f:
template = f.read()
html = template.replace('<!--Papers Come Here-->', '\n'.join(entries))
with open('index.html', 'w') as f:
f.write(html)