#!/usr/bin/env python
# -*- coding: utf-8 -*-
import os, sys, re, bibtexparser




folder=sys.argv[1] if len(sys.argv) > 1 else "bib"

if not os.path.exists(folder+'-clean'):
    os.makedirs(folder+'-clean')


for file in os.listdir(folder):
    if file.endswith(".bib"):
        print(os.path.join(folder, file))
        with open(os.path.join(folder, file)) as bibtex_file:
            content = bibtex_file.read()
            bibtex_multiline = re.sub("(,)", "\\1\n", content)
            bib_database = bibtexparser.loads(bibtex_multiline)
            for entry in bib_database.entries:
                # For some reason, keywords => keyword in bibtexparser
                entry['keywords'] = entry.get('keywords', '')
                entry['keyword'] = entry.get('keyword', '')
                if(entry['keyword'] != ''):
                    entry['keywords'] = 'cleBib/' + entry['ID'] + ', article/' + os.path.splitext(file)[0] + ', ' + entry['keyword']
                else:
                    entry['keywords'] = 'cleBib/' + entry['ID'] + ', article/' + os.path.splitext(file)[0]
                del entry['keyword']
            with open(os.path.join(folder+'-clean', file), 'w') as bibtex_export:
                bibtex_export_str = bibtexparser.dumps(bib_database)
                bibtex_export.write(bibtex_export_str.encode('utf8'))

#!/usr/bin/env python
# -*- coding: utf-8 -*-
import os, sys, bibtexparser
from bibtexparser.bparser import BibTexParser
from bibtexparser.bwriter import BibTexWriter


folder=sys.argv[1] if len(sys.argv) > 1 else "bib"

if os.path.exists(folder+'-clean'):
    print 'cleaning '+folder+'-clean/'
    for file in os.listdir(folder+'-clean'):
        try:
            if os.path.isfile(folder+'-clean/'+file):
                os.unlink(folder+'-clean/'+file)
        except Exception as e:
            print(e)
else:
    os.makedirs(folder+'-clean')

#Writer customization
writer = BibTexWriter()
writer.contents = ['entries']
writer.indent = '  '
writer.order_entries_by = ('ENTRYTYPE', 'author', 'year')

print 'Parsing files in '+folder+'/'
for file in os.listdir(folder):
    if file.endswith(".bib"):
        print(os.path.join(folder, file))
        with open(os.path.join(folder, file)) as bibtex_file:
            bib_database = bibtexparser.load(bibtex_file)
            for entry in bib_database.entries:
                entry['keywords'] = entry.get('keywords', '')
                if(entry['keywords'] != ''):
                    entry['keywords'] = 'cleBib/' + entry['ID'] + ', article/' + os.path.splitext(file)[0] + ', ' + entry['keywords']
                else:
                    entry['keywords'] = 'cleBib/' + entry['ID'] + ', article/' + os.path.splitext(file)[0]
            with open(os.path.join(folder+'-clean', file), 'w') as bibtex_export:
                bibtex_export_str = bibtexparser.dumps(bib_database, writer)
                bibtex_export.write(bibtex_export_str.encode('utf8'))

upgrade to v1.0.1