#!/usr/bin/env python # tsv2index.py - given a few configurations, ouput an html file # usage: ./bin/tsv2index.py > ./index.html # Eric Lease Morgan # (c) University of Notre Dame; distributed under a GNU Public License # April 1, 2024 - first cut # configure TSV = './index.tsv' ITEM = '
  • ##TITLE## - ##DESCRIPTION##
  • ' TEMPLATE = './etc/template.htm' # require from datetime import datetime from pandas import read_csv # read the metadata and sort it metadata = read_csv( TSV, sep='\t' ) metadata.sort_values(by=[ 'date' ], ascending=False, inplace=True ) # process each metadata item; create a list of... list items listitems = [] for index, item in metadata.iterrows() : # parse author = item[ 'creator' ] title = item[ 'title' ] date = item[ 'date' ] description = item[ 'description' ] subjects = item[ 'subjects' ] identifier = item[ 'identifier' ] # build a list item listitem = ITEM.replace( '##TITLE##', title ).replace( '##DESCRIPTION##', description ) listitem = listitem.replace( '##SUBJECTS##', subjects ).replace( '##DATE##', date ) listitem = listitem.replace( '##IDENTIFIER##', identifier ) # update listitems.append( listitem ) # build date date = datetime.now().strftime( '%B %-d, %Y' ) # build html with open ( TEMPLATE ) as handle : html = handle.read() html = html.replace( '##LISTITEMS##', '\n'.join( listitems ) ).replace( '##DATE##', date ) # output and done print( html ) exit()