+++ /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(dirname, category, basename):
- filename = '{}.bib'.format(category)
- if not os.path.exists(filename):
- return (None, 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))
- with open('{}_bib.html'.format(filename.rsplit('.', 1)[0]), 'r') as f:
- bib = f.read().split('<hr>')[0].strip().split('\n\n', 2)[2]
- return (html, bib)
-
-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']
-
- outhtml = []
- outbibl = []
- outhtml.append('% use aam ueberschrift="Publikationen"')
- outbibl.append('% use aam ueberschrift="BibTeX"')
- with tempfile.TemporaryDirectory() as tmpdir:
- split_bibtex(tmpdir, filename, categories)
- cwd = os.getcwd()
- os.chdir(tmpdir)
- for (cat, name) in zip(categories, catnames):
- (html, bib) = get_publications(tmpdir, cat, basename)
- if html is None:
- continue
- outhtml.append('<h2 id="{}">{}</h2>'.format(cat, name))
- outhtml.append(html)
- outbibl.append(bib)
- os.chdir(cwd)
-
- with open('{}.html'.format(basename), 'w') as f:
- f.write('\n'.join(outhtml))
- with open('{}_bib.html'.format(basename), 'w') as f:
- f.write('\n'.join(outbibl))
-
- print('DONE! Now please copy {}.html and {}_bib.html to the webserver.'.format(basename, basename))
--- /dev/null
+#!/usr/bin/env python3
+
+import os
+import tempfile
+import subprocess
+import sys
+
+# Not used currently
+# 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(dirname, category, basename):
+ filename = '{}.bib'.format(category)
+ if not os.path.exists(filename):
+ return (None, 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))
+ with open('{}_bib.html'.format(filename.rsplit('.', 1)[0]), 'r') as f:
+ bib = f.read().split('<hr>')[0].strip().split('\n\n', 2)[2]
+ return (html, bib)
+
+if __name__ == '__main__':
+ if len(sys.argv) != 1:
+ print('Usage: {}'.format(sys.argv[0]), file=sys.stderr)
+ sys.exit(1)
+
+ basename = 'pubs'
+ categories = ['preprints', 'articles', 'books', 'proceedings', 'theses']
+ catnames = ['Preprints', '<de>Zeitschriftenartikel</de><en>Journal articles</en>', '<de>Bücher</de><en>Books</en>', 'Proceedings', '<de>Abschlussarbeiten</de><en>Theses</en>']
+
+ outhtml = []
+ outbibl = []
+
+ outhtml.append('% use aam ueberschrift="Publikationen"')
+ outbibl.append('% use aam ueberschrift="BibTeX"')
+ outhtml.append('<hr />')
+ outhtml.append('<div class="contents-vertical">')
+ outhtml.append('<ul>')
+
+ for (cat, name) in zip(categories, catnames):
+ outhtml.append('<li><a href="#{}">{}</a>'.format(cat, name))
+ outhtml.append('</ul>')
+ outhtml.append('<hr />')
+ outhtml.append('</div>')
+
+ for (cat, name) in zip(categories, catnames):
+ (html, bib) = get_publications(os.getcwd(), cat, basename)
+ if html is None:
+ continue
+ outhtml.append('<h2 id="{}">{}</h2>'.format(cat, name))
+ outhtml.append(html)
+ outbibl.append(bib)
+
+ with open('{}.html'.format(basename), 'w') as f:
+ f.write('\n'.join(outhtml) + '\n')
+ with open('{}_bib.html'.format(basename), 'w') as f:
+ f.write('\n'.join(outbibl) + '\n')
+
+ print('DONE! Now please copy {}.html and {}_bib.html to the webserver.'.format(basename, basename))