Skip to content

Instantly share code, notes, and snippets.

@chaosct
Last active September 26, 2016 17:08
Show Gist options
  • Save chaosct/254d896a262d7438dff7 to your computer and use it in GitHub Desktop.
Save chaosct/254d896a262d7438dff7 to your computer and use it in GitHub Desktop.
Script to clean (and sort) the bibfile exported by Mendeley
# Script to clean (and sort) the bibfile exported by mendeley
# It is then apt for versioning
# Author: Carles F. Julià <carles.fernandez(AT)upf.edu>
# You will need bibtexparser package:
# $ pip install bibtexparser
# usage: cleanbib.py library.bib
# WARNING: it overwrites the original file
import bibtexparser
from bibtexparser.bparser import BibTexParser
if __name__ == '__main__':
import sys
bibfile = sys.argv[1]
with open(bibfile) as bibtex_file:
parser = BibTexParser()
bib_database = bibtexparser.load(bibtex_file, parser=parser)
for entry in bib_database.entries:
for k in ('file','annote','abstract'):
entry.pop(k,None)
bibtex_string = bibtexparser.dumps(bib_database)
with open(bibfile,'w') as bibtex_file:
bibtex_file.write(bibtex_string.encode('utf8'))
@emanuelealiverti
Copy link

great work! I also suggest to add at line 22
'isbn', 'mendeley-groups', 'keywords', 'file'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment