Adding KBART metadata export to Janeway

Janeway Dev Team
2 min readFeb 15, 2021

--

By MPE

This evening’s hack fun for me (MPE) was to add KBART metadata export into Janeway. This took 39 minutes. KBART is a metadata standard that makes it easy for libraries to ingest content into their catalogues.

The quite frankly very horrible logo for KBART
KBART

So, what did I do. Well, first, I added a URL route in our api call:

url(r'^kbart/csv$', views.kbart, name='kbart'),
url(r'^kbart/tsv$', views.kbart_tsv, name='kbart'),

This means that at https://press.com you will now find two urls https://press.com/api/kbart/csv and https://press.com/api/kbart/tsv that will be the endpoints for this metadata output.

The KBART specification states that fields should be tab delimited but I’ve decided to also include CSV output because it’s neater.

The KBART generation code consists of two functions (one of which is just the TSV wrapper):

def kbart_tsv(request):
return kbart(request, delim='\t')


def kbart(request, delim=','):
"""
Produces KBART metadata output
@param request: the request object
@return: a rendered CSV
"""
fields = ["date_first_issue_online", "num_first_vol_online", "num_first_issue_online", "date_last_issue_online",
"num_last_vol_online", "num_last_issue_online", "title_url", "first_author", "title_id", "embargo_info",
"coverage_depth", "notes", "publisher_name", "publication_type", "date_monograph_published_print",
"date_monograph_published_online", "monograph_volume", "monograph_edition", "first_editor",
"parent_publication_title_id", "preceding_publication_title_id", "access_type"]

response = HttpResponse(content_type='text/csv')

if delim == ',':
writer = csv.DictWriter(response, fieldnames=fields)
response['Content-Disposition'] = 'attachment; filename="kbart.csv"'
else:
writer = csv.DictWriter(response, fieldnames=fields, delimiter='\t')
response['Content-Disposition'] = 'attachment; filename="kbart.tsv"'

writer.writeheader()

for journal in request.press.journals():
journal_line = {}
issues = journal.issues()
if issues.count() > 0:
journal_line['date_first_issue_online'] = '{:%Y-%m-%d}'.format(issues.order_by('date')[0].date)
journal_line['num_first_vol_online'] = issues.order_by('date')[0].volume
journal_line['num_first_issue_online'] = issues.order_by('date')[0].issue
journal_line['date_last_issue_online'] = '{:%Y-%m-%d}'.format(issues.order_by('-date')[0].date)
journal_line['num_last_vol_online'] = issues.order_by('-date')[0].volume
journal_line['num_last_issue_online'] = issues.order_by('-date')[0].issue

journal_line['title_url'] = journal.full_url()
journal_line['coverage_depth'] = 'fulltext'
journal_line['publisher_name'] = request.press.name
journal_line['publication_type'] = 'serial'
journal_line['title_id'] = journal.issn
journal_line['access_type'] = 'F'

writer.writerow(journal_line)

return response

As you can see, this just pulls out the details of each journal and writes everything it can to the file. And… tada. We now have KBART support for all Janeway titles. I hope this will be merged into the next update.

— Martin Paul Eve

--

--

Janeway Dev Team
Janeway Dev Team

Written by Janeway Dev Team

We are Andy, Mauro, Joe and Martin and we develop the Janeway publishing platform.

No responses yet