예제 #1
0
    def __write_list_publications_md(self, global_index, filtered_bibkeys,
                                     string_rules):
        html_format = bibtexformatter.HTML_Formatter(string_rules)

        dict_pubs = {}
        for bib_key in filtered_bibkeys:
            bib_key = bib_key.lower()
            try:
                html_bibkey, year, pub_type, pub_details = self.__append_publication_md(
                    global_index, bib_key, html_format)
                pub_details = pub_details.replace('_', ' ').strip()
                dict_pubs[bib_key] = {}
                dict_pubs[bib_key]['html'] = html_bibkey
                dict_pubs[bib_key]['year'] = int(year)
                dict_pubs[bib_key]['pub_type'] = pub_type
                dict_pubs[bib_key]['pub_details'] = pub_details
                if pub_type.lower() == '@phdthesis':
                    dict_pubs[bib_key]['author_name'] = global_index[
                        bib_key].entry['author']
                    dict_pubs[bib_key]['title_thesis'] = global_index[
                        bib_key].entry['title']
                    # TODO this is a hardcode capital first letter of bibkey
                    dict_pubs[bib_key]['coverpng'] = bib_key[0].title(
                    ) + bib_key[1:] + '.png'
            except:
                print(
                    f"Failed writing html for publication list for {bib_key}, skipping this entry."
                )
                print(traceback.format_exc())
        return dict_pubs
def write_list_publications_md(global_index, filtered_publications, out_dir,
                               string_rules):
    html_format = bibtexformatter.HTML_Formatter(string_rules)

    md_format = 'title: Publications\n\n'
    md_format += '<ul>\n'

    for bib_key in filtered_publications:
        md_format += append_publication_md(global_index,
                                           bib_key,
                                           html_format,
                                           go_parent_dir=False)

    md_format += '</ul>\n'
    # publications.md
    out_path = out_dir + '.md'

    write_md_pass(out_path, md_format)
def write_author_publications_md(global_index, author_index, list_researchers,
                                 out_dir, string_rules):
    list_bibs_error = []
    html_format = bibtexformatter.HTML_Formatter(string_rules)

    for researcher_names in list_researchers:
        full_name = "-".join(researcher_names)
        title_md = " ".join(researcher_names).title()  # camel case
        md_format = 'title: Publications of ' + title_md + '\n'
        md_format += 'template: publications-author\n'
        md_format += 'author: ' + "-".join(researcher_names) + '\n'
        md_format += 'author_name: ' + title_md + '\n'
        list_pubs_author = []
        for author_name in author_index.keys():
            if researcher_names[-1] == author_name.lower():
                for bib_key in author_index[author_name]:
                    list_pubs_author.append(bib_key)
        md_format += 'bibkeys: ' + ','.join(list_pubs_author)

        out_path = os.path.join(out_dir, full_name + '.md')

        write_md_pass(out_path, md_format)
def write_list_publications_md(global_index, filtered_publications, out_dir,
                               string_rules):
    html_format = bibtexformatter.HTML_Formatter(string_rules)

    dict_pubs = {}
    for bib_key in filtered_publications:
        bib_key = bib_key.lower()
        html_bibkey, year, pub_type, pub_details = append_publication_md(
            global_index, bib_key, html_format, go_parent_dir=False)
        dict_pubs[bib_key] = {}
        dict_pubs[bib_key]['html'] = html_bibkey
        dict_pubs[bib_key]['year'] = int(year)
        dict_pubs[bib_key]['pub_type'] = pub_type
        dict_pubs[bib_key]['pub_details'] = pub_details
        if pub_type.lower() == '@phdthesis':
            dict_pubs[bib_key]['author_name'] = global_index[bib_key].entry[
                'author']
            dict_pubs[bib_key]['title_thesis'] = global_index[bib_key].entry[
                'title']
            # TODO this is a hardcode capital first letter of bibkey
            dict_pubs[bib_key]['coverpng'] = bib_key[0].title(
            ) + bib_key[1:] + '.png'
    return dict_pubs
def write_author_publications_md(global_index, author_index, list_researchers,
                                 out_dir, string_rules):
    list_bibs_error = []
    html_format = bibtexformatter.HTML_Formatter(string_rules)

    for researcher_names in list_researchers:
        full_name = "-".join(researcher_names)
        title_md = " ".join(researcher_names).title()  # camel case
        md_format = 'title: Publications of ' + title_md + '\n'
        md_format += 'template: publication-list\n\n'
        md_format += '<ul>\n'

        for author_name in author_index.keys():
            if researcher_names[-1] == author_name.lower():
                for bib_key in author_index[author_name]:
                    md_format += append_publication_md(global_index,
                                                       bib_key,
                                                       html_format,
                                                       go_parent_dir=True)

        md_format += '</ul>\n'
        out_path = os.path.join(out_dir, full_name + '.md')

        write_md_pass(out_path, md_format)
예제 #6
0
    def __write_single_publication_md(self, global_index, string_rules,
                                      filtered_bibkeys, out_dir):
        html_format = bibtexformatter.HTML_Formatter(string_rules)

        list_bibs_error = []
        for bibkey in filtered_bibkeys:
            try:
                md_format = ''

                if 'author' not in global_index[
                        bibkey].entry or 'title' not in global_index[
                            bibkey].entry:
                    # It skips bibkeys either without authors or title
                    continue

                global_index = self.__cleanup_global_index(
                    global_index, bibkey)
                authors_format = bibtexformatter.authors_to_string(
                    global_index[bibkey].author)
                title = codecs.decode(global_index[bibkey].entry['title'],
                                      "ulatex")
                md_format += 'title: ' + title + '\n'
                md_format += 'authors: ' + authors_format + '\n'
                pub_type = global_index[bibkey].entry_type
                has_pdf = 'file' in global_index[bibkey].entry
                md_format += 'has_pdf: ' + str(has_pdf) + '\n'
                if pub_type.lower() == '@phdthesis':
                    md_format += 'template: publication-thesis\n'
                    # TODO this is a hardcode capital first letter of bibkey
                    md_format += 'coverpng: ' + bibkey[0].title(
                    ) + bibkey[1:] + '.png\n'
                    for k in 'promotor', 'copromotor', 'school', 'optmonth', 'year':
                        if k in global_index[bibkey].entry:
                            md_format += k + ': ' + global_index[bibkey].entry[
                                k] + '\n'
                    if 'url' in global_index[bibkey].entry:
                        url_pub = global_index[bibkey].entry['url']
                        md_format += 'urlweb: ' + url_pub + '\n'
                else:
                    md_format += 'template: publication\n'
                    md_format += 'bibkey: ' + bibkey + '\n'
                    if 'booktitle' in global_index[
                            bibkey].entry or 'journal' in global_index[
                                bibkey].entry:
                        event_type = 'journal' if 'journal' in global_index[
                            bibkey].entry else 'booktitle'
                        if global_index[bibkey].entry[
                                event_type] in string_rules:
                            event_name = string_rules[
                                global_index[bibkey].entry[event_type]]
                        else:
                            event_name = global_index[bibkey].entry[event_type]
                        event_name = event_name.replace('_', ' ').strip()
                        md_format += 'published_in: ' + event_name + '\n'
                        _, pub_details = html_format.apply(
                            global_index[bibkey])
                        pub_details = pub_details.replace('_', ' ').strip()
                        md_format += 'pub_details: ' + pub_details + '\n'

                    md_format_bibitem, is_preprint = self.__format_bibitem(
                        global_index[bibkey], is_html_format=False)
                    md_format += md_format_bibitem

                if 'abstract' in global_index[bibkey].entry:
                    md_format += global_index[bibkey].entry['abstract'] + '\n\n'

                # if 'file' in global_index[bibitem].entry:
                # TODO: Disabled for now as we don't have a version of the PDFs on the new website
                #     md_format += 'A <b>pdf file</b> of this publication is available for personal use.'
                #     md_format += 'Enter your e-mail address in the box below and press the button. '
                #     md_format += 'You will receive an e-mail message with a link to the pdf file.\n'
                #
                #     md_format += '<form action=\"sender.php\">'  # TODO implement sender.php
                #     md_format += '  <input type=\"text\" name=\"email\">'
                #     md_format += '  <input type=\"submit\" value=\"Send ' + global_index[bibitem].entry[
                #       'file'] + ' by e-mail\">'
                #     md_format += '</form>'

                md_format = md_format.replace('{', '').replace('}', '')
                out_path = os.path.join(out_dir, bibkey + '.md')

                file = open(out_path, 'w')

                try:  # This is ugly but necessary for now to avoid UnicodeEncodeError
                    file.write(md_format)
                    file.close()
                except UnicodeEncodeError:
                    list_bibs_error.append(bibkey)
            except Exception as exc:
                print(f"Failed writing bib entry {bibkey} to markdown file.")
                print(traceback.format_exc())

        print('List of bibkeys returning UnicodeEncodeError')
        for bib in list_bibs_error:
            print(bib)
def write_single_publication_md(global_index, string_rules,
                                filtered_publications, out_dir, json_path):
    html_format = bibtexformatter.HTML_Formatter(string_rules)

    list_bibs_error = []
    for bibitem in filtered_publications:
        md_format = ''

        if 'author' not in global_index[
                bibitem].entry or 'title' not in global_index[bibitem].entry:
            # It skips bibitems with absence of authors or title
            continue

        for attr_key in global_index[bibitem].entry:
            global_index[bibitem].entry[attr_key] = global_index[
                bibitem].entry[attr_key].replace('{', '').replace('}', '')
        authors_format = bibtexformatter.authors_to_string(
            global_index[bibitem].author)
        title = codecs.decode(global_index[bibitem].entry['title'], "ulatex")
        md_format += 'title: ' + title + '\n'
        md_format += 'authors: ' + authors_format + '\n'

        pub_type = global_index[bibitem].entry_type
        if pub_type.lower() == '@phdthesis':
            md_format += 'template: publication-thesis\n'
            # TODO this is a hardcode capital first letter of bibkey
            md_format += 'coverpng: ' + bibitem[0].title(
            ) + bibitem[1:] + '.png\n'
            for k in 'promotor', 'copromotor', 'school', 'optmonth', 'year':
                if k in global_index[bibitem].entry:
                    md_format += k + ': ' + global_index[bibitem].entry[
                        k] + '\n'
        else:
            md_format += 'template: publication\n'
            if 'booktitle' in global_index[
                    bibitem].entry or 'journal' in global_index[bibitem].entry:
                event_type = 'journal' if 'journal' in global_index[
                    bibitem].entry else 'booktitle'
                if global_index[bibitem].entry[event_type] in string_rules:
                    event_name = string_rules[
                        global_index[bibitem].entry[event_type]]
                    event_name = event_name.replace('_', ' ').strip()
                else:
                    event_name = global_index[bibitem].entry[event_type]
                md_format += 'published_in: ' + event_name + '\n'
                _, pub_details = html_format.apply(global_index[bibitem])
                md_format += 'pub_details: ' + pub_details + '\n'

            if 'doi' in global_index[bibitem].entry:
                md_format += 'doi: ' + 'https://doi.org/' + global_index[
                    bibitem].entry['doi'] + '\n'
            if 'url' in global_index[bibitem].entry and 'arxiv' in global_index[
                    bibitem].entry['url']:
                md_format += 'arxiv: ' + global_index[bibitem].entry[
                    'url'] + '\n'
            if 'pmid' in global_index[bibitem].entry:
                url_pmid = 'http://www.ncbi.nlm.nih.gov/pubmed/' + global_index[
                    bibitem].entry['pmid']
                md_format += 'pmid: ' + url_pmid + '\n'
        if 'abstract' in global_index[bibitem].entry:
            md_format += global_index[bibitem].entry['abstract'] + '\n\n'

        # if 'file' in global_index[bibitem].entry:
        # TODO: Disabled for now as we don't have a version of the PDFs on the new website
        #     md_format += 'A <b>pdf file</b> of this publication is available for personal use.'
        #     md_format += 'Enter your e-mail address in the box below and press the button. '
        #     md_format += 'You will receive an e-mail message with a link to the pdf file.\n'
        #
        #     md_format += '<form action=\"sender.php\">'  # TODO implement sender.php
        #     md_format += '  <input type=\"text\" name=\"email\">'
        #     md_format += '  <input type=\"submit\" value=\"Send ' + global_index[bibitem].entry[
        #       'file'] + ' by e-mail\">'
        #     md_format += '</form>'

        md_format = md_format.replace('{', '').replace('}', '')
        out_path = os.path.join(out_dir, bibitem + '.md')

        file = open(out_path, 'w')

        try:  # This is ugly but necessary for now to avoid UnicodeEncodeError
            file.write(md_format)
            file.close()
        except UnicodeEncodeError:
            list_bibs_error.append(bibitem)
    print('List of bibkeys returning UnicodeEncodeError')

    for bib in list_bibs_error:
        print(bib)