def names2(s): return [(debr(first), debr(' '.join(n for n in (prelast, last) if n)), debr(lineage)) for prelast, last, first, lineage in _bibtex.names(s)]
def names2(s): # pragma: no cover return [(debr(first), debr(' '.join(n for n in (prelast, last) if n)), debr(lineage)) for prelast, last, first, lineage in _bibtex.names(s)]
last = sa.Column(sa.Text, nullable=False) given = sa.Column(sa.Text, nullable=False) lineage = sa.Column(sa.Text, nullable=False) engine = sa.create_engine(DB) Entry.metadata.drop_all(engine) Entry.metadata.create_all(engine) for b in BIBFILES: print(b.filepath) with engine.begin() as conn: insert_entry = Entry.__table__.insert(bind=conn).execute insert_contrib = Contributor.__table__.insert(bind=conn).execute for bibkey, (entrytype, fields) in b.iterentries(): pk, = insert_entry(filename=b.filename, bibkey=bibkey, entrytype=entrytype, fields=fields, glottolog_ref_id=fields.get('glottolog_ref_id'), author=fields.get('author'), editor=fields.get('editor'), year=fields.get('year'), title=fields.get('title') ).inserted_primary_key contribs = [{'entry_pk': pk, 'role': role, 'index': i, 'prelast': prelast, 'last': last, 'given': given, 'lineage': lineage} for role in ('author', 'editor') for i, (prelast, last, given, lineage) in enumerate(_bibtex.names(fields.get(role, '')), 1)] if contribs: insert_contrib(contribs)
for b in BIBFILES: print(b.filepath) with engine.begin() as conn: insert_entry = Entry.__table__.insert(bind=conn).execute insert_contrib = Contributor.__table__.insert(bind=conn).execute for bibkey, (entrytype, fields) in b.iterentries(): pk, = insert_entry(filename=b.filename, bibkey=bibkey, entrytype=entrytype, fields=fields, glottolog_ref_id=fields.get('glottolog_ref_id'), author=fields.get('author'), editor=fields.get('editor'), year=fields.get('year'), title=fields.get('title')).inserted_primary_key contribs = [ { 'entry_pk': pk, 'role': role, 'index': i, 'prelast': prelast, 'last': last, 'given': given, 'lineage': lineage } for role in ('author', 'editor') for i, (prelast, last, given, lineage ) in enumerate(_bibtex.names(fields.get(role, '')), 1) ] if contribs: insert_contrib(contribs)