From: Philipp Falk Date: Tue, 6 Sep 2016 13:15:02 +0000 (+0200) Subject: bibtex.py: better creation of bibtex source html X-Git-Url: https://vcs.mathematik.uni-freiburg.de/gitweb//gitweb/index.cgi?a=commitdiff_plain;h=12b349a0a4475a251f15a6d98b156af6eb6f3c57;p=philipp%2Fscripts bibtex.py: better creation of bibtex source html --- diff --git a/bibtex.py b/bibtex.py index 09844cd..606989f 100755 --- 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('
')[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('
')[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('

{}

'.format(name)) - out.append(html) + outhtml.append('

{}

'.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))