--- /dev/null
+#!/usr/bin/env python3
+
+import os
+import tempfile
+import subprocess
+import sys
+
+def split_bibtex(dirname, filename, categories):
+ for cat in categories:
+ cmd = ['bib2bib', '-q', '-c', '$type="{}"'.format(cat), '--warn-error',
+ '-ob', os.path.join(dirname, '{}.bib'.format(cat)),
+ filename]
+ try:
+ subprocess.check_call(cmd)
+ except subprocess.CalledProcessError as e:
+ if e.returncode != 2:
+ raise e
+ return tmpdir
+
+def get_publications_html(dirname, category, basename):
+ filename = '{}.bib'.format(category)
+ if not os.path.exists(filename):
+ return None
+ cmd = ['bibtex2html', '-q', '--no-doc', '--no-header',
+ filename]
+ subprocess.check_call(cmd)
+ with open('{}.html'.format(filename.rsplit('.', 1)[0]), 'r') as f:
+ html = f.read().split('<hr>')[0].strip().replace('{}_bib.html'.format(category), '{}_bib.html'.format(basename))
+ return html
+
+if __name__ == '__main__':
+ if len(sys.argv) != 2:
+ print('Usage: {} <file.bib>'.format(sys.argv[0]), file=sys.stderr)
+ sys.exit(1)
+
+ filename = sys.argv[1]
+ basename = filename.rsplit('.', 1)[0]
+ categories = ['preprint', 'article', 'book', 'proceeding', 'thesis']
+ catnames = ['Preprints', 'Zeitschriftenartikel', 'Bücher', 'Proceedings', 'Abschlussarbeiten']
+
+ out = []
+ out.append('% use aam ueberschrift="Publikationen"')
+ with tempfile.TemporaryDirectory() as tmpdir:
+ split_bibtex(tmpdir, filename, categories)
+ cwd = os.getcwd()
+ os.chdir(tmpdir)
+ for (cat, name) in zip(categories, catnames):
+ html = get_publications_html(tmpdir, cat, basename)
+ if html is None:
+ continue
+ out.append('<h2>{}</h2>'.format(name))
+ out.append(html)
+ os.chdir(cwd)
+
+ subprocess.check_call(['bibtex2html', '-q', filename])
+ with open('{}.html'.format(basename), 'w') as f:
+ f.write('\n'.join(out))
+
+ print('DONE! Now please copy {}.html and {}_bib.html to the webserver.'.format(basename, basename))