bibtex.py: better creation of bibtex source html
authorPhilipp Falk <philipp@email.mathematik.uni-freiburg.de>
Tue, 6 Sep 2016 13:15:02 +0000 (15:15 +0200)
committerPhilipp Falk <philipp@email.mathematik.uni-freiburg.de>
Tue, 6 Sep 2016 13:15:02 +0000 (15:15 +0200)
bibtex.py

index 09844cd..606989f 100755 (executable)
--- a/bibtex.py
+++ b/bibtex.py
@@ -17,16 +17,18 @@ def split_bibtex(dirname, filename, categories):
                     raise e
         return tmpdir
 
-def get_publications_html(dirname, category, basename):
+def get_publications(dirname, category, basename):
     filename = '{}.bib'.format(category)
     if not os.path.exists(filename):
-        return None
+        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))
-    return html
+    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:
@@ -38,22 +40,26 @@ if __name__ == '__main__':
     categories = ['preprint', 'article', 'book', 'proceeding', 'thesis']
     catnames = ['Preprints', 'Zeitschriftenartikel', 'Bücher', 'Proceedings', 'Abschlussarbeiten']
 
-    out = []
-    out.append('% use aam ueberschrift="Publikationen"')
+    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 = get_publications_html(tmpdir, cat, basename)
+            (html, bib) = get_publications(tmpdir, cat, basename)
             if html is None:
                 continue
-            out.append('<h2>{}</h2>'.format(name))
-            out.append(html)
+            outhtml.append('<h2>{}</h2>'.format(name))
+            outhtml.append(html)
+            outbibl.append(bib)
         os.chdir(cwd)
 
-    subprocess.check_call(['bibtex2html', '-q', filename])
     with open('{}.html'.format(basename), 'w') as f:
-        f.write('\n'.join(out))
+        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))