Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Export DocumentSet to bibtex #12

Open
stijnh opened this issue Mar 3, 2022 · 1 comment
Open

Export DocumentSet to bibtex #12

stijnh opened this issue Mar 3, 2022 · 1 comment
Labels
enhancement New feature or request good first issue Good for newcomers help wanted Extra attention is needed

Comments

@stijnh
Copy link
Member

stijnh commented Mar 3, 2022

Currently, there is no way to export results after loading them into memory. On possibility would be to add the ability to export a DocumentSet to a bibtex file.

@stijnh stijnh added enhancement New feature or request help wanted Extra attention is needed good first issue Good for newcomers labels Mar 3, 2022
@stephen-pilli
Copy link

Hopefully this workaround will help.

import bibtexparser

def export_documentset_to_bibtex(document_set, output_filename="exported_file.bib"):
    """
    Exports entries from a litstudy DocumentSet to a .bib file.

    Parameters:
        document_set (DocumentSet): A litstudy DocumentSet containing documents to export.
        output_filename (str): The name of the output .bib file (default: "exported_file.bib").
    """
    # Convert DocumentSet entries to bibtexparser format
    bibtex_entries = []
    for entry in document_set:
        bibtex_entry = entry.entry
        bibtex_entries.append(bibtex_entry)

    # Create a BibDatabase object and set entries
    bib_database = bibtexparser.bibdatabase.BibDatabase()
    bib_database.entries = bibtex_entries

    # Write entries to the output BibTeX file
    with open(output_filename, "w") as bibfile:
        bibtexparser.dump(bib_database, bibfile)

    print(f"BibTeX file exported successfully as '{output_filename}'")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants