Skip to content

Instantly share code, notes, and snippets.

@phette23
Created September 16, 2022 18:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save phette23/76f85593f53162a7cedc1dbcc3c2d74a to your computer and use it in GitHub Desktop.
Save phette23/76f85593f53162a7cedc1dbcc3c2d74a to your computer and use it in GitHub Desktop.
Convert KBART to Serials Solution 360 Core database template
'''
Translate KBART file from OAPEN into Serials Solutions Client Center aka 360
Core database format. See the DatabaseTemplate.txt file for details.
'''
import csv
def get_first_isbn(isbns):
""" return the first in a list of semicolon-separated ISBNs
Args:
isbn_string (str): list of one or more ISBNS in a string, e.g.
"9781478090359; 9780822372646; 9780822368687; 9780822368564"
Returns:
isbn (str): the first ISBN in the list string
("9781478090359" in the example above)
"""
return isbns.split(';')[0]
with open('Profile_5_OAPEN_KBART.csv', 'r') as kbart:
reader = csv.DictReader(kbart, delimiter='\t')
with open('db.csv', 'w') as db:
fields = ("Title (Required)", "Type (Required)", "Default URL", "Publisher", "Publication Date (Book)", "Public Note", "Display Public Note", "Location Note", "Display Location Note", "ISSN (Journal)", "Coverage Date From (Journal)", "Coverage Date To (Journal)", "ISBN (Book)", "Author (Book)", "Editor (Book)", "Edition (Book)", "Language ID", "Alphabetization")
writer = csv.DictWriter(db, fieldnames=fields)
writer.writeheader()
for row in reader:
writer.writerow({
"Title (Required)": row['publication_title'],
"Type (Required)": 'Book',
"Default URL": row['title_url'],
"Publisher": row['publisher_name'],
"Publication Date (Book)": row['date_monograph_published_print'],
# "Public Note": row[''],
# "Display Public Note": row[''],
# "Location Note": row[''],
# "Display Location Note": row[''],
# "ISSN (Journal)": row[''],
# "Coverage Date From (Journal)": row[''],
# "Coverage Date To (Journal)": row[''],
"ISBN (Book)": get_first_isbn(row['print_identifier']),
"Author (Book)": row['first_author'],
"Editor (Book)": row['first_editor'],
"Edition (Book)": row['monograph_edition'],
# "Language ID": row[''],
# "Alphabetization": row[''],
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment