-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathscholar.py
30 lines (25 loc) · 986 Bytes
/
scholar.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
import bibtexparser
def parse_bibtex_file(filename):
with open(filename, 'r') as bibtex_file:
bibtex_str = bibtex_file.read()
print('hi')
bib_database = bibtexparser.loads(bibtex_str)
publications = []
for entry in bib_database.entries:
try:
title = entry.get('title', 'No title available')
authors = entry.get('author', 'No authors listed').replace(" and ", ", ")
venue = entry.get('journal', 'No venue available')
year = entry.get('year', 'No year available')
# Formatting the output
publication_info = f"{title}\n{authors}\n{venue}, {year}"
publications.append(publication_info)
except Exception as e:
print(f"Failed to process one entry: {e}")
return publications
# Example usage:
filename = "bibtex.bib"
publications = parse_bibtex_file(filename)
print(len(publications))
for pub in publications:
print(pub)