Convert BibTex file to database entries using Python

后端 未结 5 1580
星月不相逢
星月不相逢 2021-02-02 15:41

Given a bibTex file, I need to add the respective fields(author, title, journal etc.) to a table in a MySQL database (with a custom schema).

After doing some initial re

5条回答
  •  既然无缘
    2021-02-02 15:45

    My workaround is to use bibtexparser to export relevant fields to a csv file;

    import bibtexparser
    import pandas as pd
    
    with open("../../bib/small.bib") as bibtex_file:
        bib_database = bibtexparser.load(bibtex_file)
        
    df = pd.DataFrame(bib_database.entries)
    selection = df[['doi', 'number']]
    selection.to_csv('temp.csv', index=False)
    

    And then write the csv to a table in the database, and delete the temp.csv.

    This avoids some complication with pybtex I found.

提交回复
热议问题