-
Notifications
You must be signed in to change notification settings - Fork 0
/
hathifetch
executable file
·37 lines (30 loc) · 1.59 KB
/
hathifetch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#! /bin/bash
# hathifetch.sh
# Program to retrieve JSON records from Hathi Trust and extract the marc records from those JSON records.
# $Id: hathifetch.sh
E_BADARGS=65
scriptdir=$( (cd -P $(dirname $0) && pwd) )
#define the function
find_newest_file_matching_pattern_under_directory(){
echo $(find $1 -maxdepth 1 -name "$2" -print0 | xargs -0 ls -1 -t | head -1)
}
marc4j_jar=$( find_newest_file_matching_pattern_under_directory $scriptdir "marc4j*.jar" )
hathi_fetch_jar=$(find_newest_file_matching_pattern_under_directory $scriptdir/hathifetch_java "hathifetch.jar" )
if ! [ -p /dev/stdin ]
then
if [ $# -eq 0 ]
then
echo " Usage: `basename $0` [-s NumToSkip] [-n NumToReturn] file_with_ids "
echo " or : `basename $0` [-s NumToSkip] [-n NumToReturn] url_with_ids "
echo " or : cat file_with_hathi_ids | `basename $0` [-s NumToSkip] [-n NumToReturn]"
echo " other options -d = debug retrieve and print the recordURL strings only"
echo " -v = verbose fetch records and print them out as Ascii Marc"
echo " -856 = add 856 add 856 fields to the records based on the 974 fields"
echo " Note: file_with_ids can be Hathi Record numbers only (one per line), or Hathi Data listings"
echo " like the following line where the Hathi Record number is one of several entries on a line."
echo " Note also that the program supports reading gzipped input files."
exit $E_BADARGS
fi
fi
java -cp "$marc4j_jar:$hathi_fetch_jar" org.marc4j.tools.HathiPlunderer $1 $2 $3 $4 $5 $6 $7 $8 $9
exit $?