Skip to content

Instantly share code, notes, and snippets.

@tsbertalan
Created March 24, 2014 18:02
Show Gist options
  • Save tsbertalan/9745644 to your computer and use it in GitHub Desktop.
Save tsbertalan/9745644 to your computer and use it in GitHub Desktop.
'''
Quick hack to combine two BibTeX files with truly indentical entries
into one monolithic file.
Someone else could write an argparse interface to make this more reusable.
For now, I just need to get back to work.
'''
from bibtexparser.bparser import BibTexParser
with open('math.bib', 'r') as bibfile:
math = BibTexParser(bibfile)
with open('neural.bib', 'r') as bibfile:
neural = BibTexParser(bibfile)
total = dict(neural.get_entry_dict())
total.update(math.get_entry_dict())
newContent = u''
for i in total.items():
j = i[1]
t = j.pop('type')
item = '@%s{%s,\n' % (t, i[0])
for fixup in 'title', 'abstract':
if fixup in j:
j[fixup] = '{%s}' % j[fixup]
for k in j.items():
item += ' %s = {%s},\n' % (k[0], k[1])
item += '}\n\n'
newContent += item
newFileName = 'mathNeural.bib'
with open(newFileName, 'w') as newFile:
newFile.write(newContent.encode('utf8'))
print "wrote", newFileName
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment