Skip to content

Instantly share code, notes, and snippets.

@mommi84 mommi84/
Created Feb 1, 2018

What would you like to do?
Script to convert BibTeX files into RASH bibliography.
#!/usr/bin/env python
import sys
import bibtexparser
def fd(s):
if s[-1] != '.':
s += '.'
return s
def parse_bib(bib):
with open(bib) as bibtex_file:
bibtex_str =
bib_database = bibtexparser.loads(bibtex_str)
print "{} bib entries loaded.".format(len(bib_database.entries))
for entry in bib_database.entries:
print '<li id="{}" about="{}-expression" typeof="fabio:ResearchPaper" property="frbr:realizationOf" resource="{}-work" role="doc-biblioentry">'.format(entry['ID'], entry['ID'], entry['ID'])
if 'journal' not in entry:
venue = entry['booktitle']
venue = entry['journal']
except KeyError:
venue = "UNKNOWN"
authors = entry['author'].replace('{', '').replace('}', '').replace('\n', ' ').split(' and ')
auth = list()
for a in authors:
while '\\' in a:
i = a.index('\\')
a = a[:i] + a[i+2:]
if ',' in a:
aa = a.split(', ')
a = aa[0] + " " + aa[1][0] + "."
print '\t<p about="{}-expression" property="dcterms:bibliographicCitation">{} ({}). {} {}</p>'.format(entry['ID'], ", ".join(auth), entry['year'], fd(entry['title']), fd(venue))
print '</li>'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.