forked from PrincetonUniversity/SPEC
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b50dfdc
commit 8b26f02
Showing
1 changed file
with
38 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import yaml | ||
|
||
# Helper script to keep spec_refs (used to generate doxygen bibliography) | ||
# in sync with the machine readable CITATION.cff file. | ||
def cff_to_bibtex(cff_file, output_file): | ||
with open(cff_file, "r") as file: | ||
cff_data = yaml.safe_load(file) | ||
|
||
bibtex_entries = [] | ||
|
||
for ref in cff_data.get("references", []): | ||
if ref.get("type") == "article": | ||
authors = " and ".join( | ||
f"{author['given-names']} {author['family-names']}" | ||
for author in ref.get("authors", []) | ||
) | ||
bibtex_entry = ( | ||
f"@article{{{ref.get('doi', 'unknown').replace('/', '_')},\n" | ||
f" title={{ {ref.get('title')} }},\n" | ||
f" author={{ {authors} }},\n" | ||
f" journal={{ {ref.get('journal')} }},\n" | ||
f" volume={{ {ref.get('volume')} }},\n" | ||
f" number={{ {ref.get('issue', '')} }},\n" | ||
f" pages={{ {ref.get('pages', '')} }},\n" | ||
f" year={{ {ref.get('year')} }},\n" | ||
f" doi={{ {ref.get('doi')} }},\n" | ||
f" url={{ {ref.get('url')} }}\n" | ||
f"}}" | ||
) | ||
bibtex_entries.append(bibtex_entry) | ||
|
||
with open(output_file, "w") as file: | ||
file.write("\n\n".join(bibtex_entries)) | ||
|
||
print(f"BibTeX entries written to {output_file}") | ||
|
||
# Usage | ||
cff_to_bibtex("CITATION.cff", "spec_refs.bib") |