def generate_html_by_type(pubs, type_map, csl_style): html = '' batches = split_pubs_by_type(pubs, type_map) for pub_type, label in type_map.items(): if pub_type in batches: html += '\n\n<h2>' + label + '</h2>\n\n' html += generate_html(batches[pub_type], csl_style) return html
def _generate(options): bibs = None mods = None if os.path.exists(options.pids[0]): filename = options.pids[0] if filename.endswith('.bib'): with codecs.open(filename, 'r', 'utf8') as f: bibs = f.read() else: mods = _load_mods_files(options.pids) else: mods = fetch_csl_data(options.oai_api, options.oai_format, options.pids) if mods: with codecs.open(options.output_file + '.mods', 'w', 'utf8') as output_file: output_file.write(mods) if not bibs: bibs = convert_mods_to_bib(mods) with codecs.open(options.output_file + '.bib', 'w', 'utf8') as output_file: output_file.write(bibs) pubs = convert_bibtex_to_csl_data(bibs) html = options.html_preamble if options.group_by_type: html += generate_html_by_type(pubs, _type_labels, options.csl_style) else: html += generate_html(pubs, options.csl_style) html += '\n </body>\n</html>\n' with codecs.open(options.output_file + '.html', 'w', 'utf8') as output_file: output_file.write(html) generate_pdf(options.output_file, html)