Esempio n. 1
0
def single_entry_to_fulltext(entry: pybtex.Entry,
                             overwrite_key: str = None) -> str:
    """
    Converts a pybtex.Entry to text.
    """
    effective_key = entry.key if not overwrite_key else overwrite_key
    formatter = pybtex.BibliographyData(entries={effective_key: entry})
    return formatter.to_string(bib_format="bibtex")
Esempio n. 2
0
def single_entry_to_fulltext(entry: pybtex.Entry,
                             overwrite_key: str = None) -> str:
    """
    Converts a pybtex.Entry to text.

    :param entry: A pybtex.Entry.
    :param overwrite_key: A key to use instead of the default one.
    :return: A BibTeX entry as text.
    """
    effective_key = entry.key if not overwrite_key else overwrite_key
    formatter = pybtex.BibliographyData(entries={effective_key: entry})
    return formatter.to_string(bib_format="bibtex")
Esempio n. 3
0
 def write(self, fname, ids=None, **kw):
     if ids:
         bibdata = database.BibliographyData()
         for key, entry in self._bibdata.entries.items():
             if key in ids:
                 bibdata.add_entry(key, entry)
     else:
         bibdata = self._bibdata
     if bibdata.entries:
         with Path(fname).open('w', encoding='utf8') as fp:
             Writer().write_stream(bibdata, fp)
         return fname
Esempio n. 4
0
def write_bib_entries(entries, fname=None):
    """Take an iterable of pybtex.database.Entry objects, and return a string.
    If fname is not None, write the string to a file before returning it.
    """
    entries_dict = OrderedDict((e.key, e) for e in entries)
    if not entries_dict:
        return ''
    #assert len(entries) == len(entries_dict), 'Entries must have unique keys'
    btex_str = database.BibliographyData(
        entries=entries_dict).to_string('bibtex')
    if fname is not None:
        with open(fname, 'w', encoding='latin1') as f:
            f.write(btex_str)
    return btex_str
Esempio n. 5
0
def gen_refs(bibfile):
    target = os.path.splitext(os.path.split(bibfile)[1])[0] + '.yml'
    call_citeproc(bibfile, target)

    bib = ptd.parse_file(bibfile)
    ybib = yaml.load(open(target, encoding = 'utf-8'))

    for yitem in ybib['references']:
        bitem = bib.entries.get(yitem['id'])
        yitem = merge(bitem, yitem)

        newdic = dict({yitem['id'] : bitem})
        output = ptd.BibliographyData(newdic)
        output.to_file( os.path.join(BIBTEMPDIRECTORY, yitem['id'] + ".bib"), "bibtex")

    yaml.dump(ybib, open('publications.yml', 'w', encoding="utf-8"))
    return ybib
Esempio n. 6
0
 def __init__(self):
     self._bibdata = database.BibliographyData()
Esempio n. 7
0
 def empty() -> 'Biblio':
     return Biblio(bibtex.BibliographyData())