import pybtex.database from pybtex import errors import sys def bibtex_to_html(bibtex_file_path, html_file_path): # Load the BibTeX file try: bib_data = pybtex.database.parse_file(bibtex_file_path) except errors.BibliographyDataNotFoundError as e: print(f"ERROR: {e}") return # Create the HTML file with open(html_file_path, "w") as f: f.write("\n\nBibliography\n\n\n") # Write the journal papers section f.write("

Journals

\n") f.write("
\n") f.write("
    \n") # Loop through each journal entry in the BibTeX file for key, entry in bib_data.entries.items(): if "journal" in entry.fields: f.write("
  1. \n") # Write the citation key #f.write(f"{key}
    \n") # Write the authors if "author" in entry.persons: authors = entry.persons["author"] f.write("; ".join(str(author) for author in authors)) f.write("
    \n") # Write the title if "title" in entry.fields: f.write(f"{entry.fields['title']}
    \n") # Write the publication information f.write(f"{entry.fields['journal']}, ") if "volume" in entry.fields: f.write(f"vol. {entry.fields['volume']}") if "number" in entry.fields: f.write(f"({entry.fields['number']})") if "pages" in entry.fields: f.write(f", pp. {entry.fields['pages']}") if "year" in entry.fields: f.write(f", {entry.fields['year']}") f.write("
    \n") f.write("
  2. \n") f.write("
\n") # Write the conference papers section f.write("

Conferences

\n") f.write("
\n") f.write("
    \n") # Loop through each conference entry in the BibTeX file for key, entry in bib_data.entries.items(): if "booktitle" in entry.fields: f.write("
  1. \n") # Write the citation key # f.write(f"{key}
    \n") # Write the authors if "author" in entry.persons: authors = entry.persons["author"] f.write("") f.write("; ".join(str(author) for author in authors)) f.write(""); f.write("
    \n") # Write the title if "title" in entry.fields: print(entry.fields['title']) f.write(f"{entry.fields['title']}
    \n") # Write the publication information f.write(f"In {entry.fields['booktitle']}") if "pages" in entry.fields: f.write(f", pp. {entry.fields['pages']}") if "year" in entry.fields: f.write(f", {entry.fields['year']}") f.write("
    \n") f.write("
  2. \n") f.write("
\n") f.write("\n\n") if __name__ == "__main__": if len(sys.argv) != 3: print("Usage: python bibtex_to_html.py input.bib output.html") sys.exit(1) input_file_path = sys.argv[1] output_file_path = sys.argv[2] bibtex_to_html(input_file_path, output_file_path)