def ingest(cls, package="osp.fields", path="data/fields.csv"): """ Ingest fields. Args: package (str) path (str) """ reader = read_csv(package, path) for row in reader: # Sanifize field names. pf = clean_field_name(row["Primary Field"]) sf = clean_field_name(row["Secondary Field"]) # Parse abbreviations. abbrs = parse_abbrs(row["ABBRV"]) if abbrs: abbrs = filter_abbrs(abbrs) # If parent field, write row. if bool(row["Alpha Category"]): Field.create(name=pf) # Query for a parent field. field = Field.select().where(Field.name == pf).first() if field: Subfield.create(name=sf, abbreviations=abbrs, field=field)
def ingest(cls, package='osp.fields', path='data/fields.csv'): """ Ingest fields. Args: package (str) path (str) """ reader = read_csv(package, path) for row in reader: # Sanifize field names. pf = clean_field_name(row['Primary Field']) sf = clean_field_name(row['Secondary Field']) # Parse abbreviations. abbrs = parse_abbrs(row['ABBRV']) if abbrs: abbrs = filter_abbrs(abbrs) # If parent field, write row. if bool(row['Alpha Category']): Field.create(name=pf) # Query for a parent field. field = Field.select().where(Field.name == pf).first() if field: Subfield.create( name=sf, abbreviations=abbrs, field=field, )
def test_clean_field_name(dirty, clean): assert clean_field_name(dirty) == clean