-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathgenerate_bibtex.py
More file actions
56 lines (47 loc) · 1.63 KB
/
generate_bibtex.py
File metadata and controls
56 lines (47 loc) · 1.63 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
import os
from pub_data import pubs
def generate_bibtex_entry(pub):
# Generate a BibTeX key, e.g., "Author2023Title"
first_author_lastname = pub["author"][0].split()[-1]
first_word_title = pub["title"].split()[0]
bibtex_key = f"{first_author_lastname}{pub['year']}{first_word_title}"
entry_type = pub.get("type", "misc")
if entry_type == "conference":
bib_type = "inproceedings"
elif entry_type == "journal":
bib_type = "article"
else:
bib_type = "misc"
entry = f"@{bib_type}{{{bibtex_key},\n"
entry += f" title = {{{pub['title']}}},\n"
authors = []
for author in pub['author']:
if author == 'me':
authors.append('He, He')
else:
authors.append(author.title())
entry += f" author = {{{' and '.join(authors)}}},\n"
entry += f" year = {{{pub['year']}}},\n"
if "venue" in pub:
if bib_type == "inproceedings":
entry += f" booktitle = {{{pub['venue']}}},\n"
elif bib_type == "article":
entry += f" journal = {{{pub['venue']}}},\n"
if "vol" in pub:
entry += f" volume = {{{pub['vol']}}},\n"
if "page" in pub:
entry += f" pages = {{{pub['page']}}},\n"
if "url" in pub:
entry += f" url = {{{pub['url']}}},\n"
if "pdf" in pub:
entry += f" url = {{{pub['pdf']}}},\n"
if "abstract" in pub:
entry += f" abstract = {{{pub['abstract']}}},\n"
entry += "}\n"
return entry
def main():
with open("pubs.bib", "w") as f:
for pub in pubs:
f.write(generate_bibtex_entry(pub))
if __name__ == "__main__":
main()