diff --git a/bbbib.sh b/bbbib.sh index 2151f40..5d10ae5 100755 --- a/bbbib.sh +++ b/bbbib.sh @@ -27,16 +27,11 @@ done shift $((OPTIND-1)) -# bibliographe's path set? -if [[ -z "$BIBLIOGRAPHE_PATH" ]]; then - echo "No bibliographe"; - exit; -fi - # bibliography exists? if [[ -z "$BIB" ]]; then echo "No bibliography" exit; fi -node $BIBLIOGRAPHE_PATH/refactorbib.js --data $BIB --index --print +./parse/refactorbib.py -i $BIB +#node $BIBLIOGRAPHE_PATH/refactorbib.js --data $BIB --index --print diff --git a/nnnew.sh b/nnnew.sh index fb21a21..894a1ef 100755 --- a/nnnew.sh +++ b/nnnew.sh @@ -96,7 +96,7 @@ touch notes.mmd if [ -z "$BIBLIOGRAPHE_PATH" ]; then echo "No bibliographe" else - node $BIBLIOGRAPHE_PATH/refactorbib.js --data $BIB > tmpbib.json + ./parse/refactorbib.py $BIB > tmpbib.json REFERENCE=$(node $BIBLIOGRAPHE_PATH/generatebib.js --data tmpbib.json --items [\"$REF\"] --output md) AUTHOR=$(whoami) DATE=$(date +%Y\-%m\-%d) diff --git a/parse/refactorbib.py b/parse/refactorbib.py new file mode 100755 index 0000000..cf6113a --- /dev/null +++ b/parse/refactorbib.py @@ -0,0 +1,63 @@ +#!/usr/bin/env python +import sys, os, json +from optparse import OptionParser + +def open_file(p): + if not os.path.exists(p): + sys.exit('File %s does not exists... Aborting.' % p) + return open(p, 'rb') + +def refactor(data): + + data_out = {} + for d in data: + nid = '' + if(d['author']): + nid = d['author'][0]['family'] + d['issued']['date-parts'][0][0] + elif(d['editor']): + nid = d['editor'][0]['family'] + d['issued']['date-parts'][0][0] + + if nid in data_out: + for c in range(97, 122): + nid = nid + chr(c) + if not nid in data: + break + data_out[nid] = d + + return data_out + + +if __name__ == '__main__': + + p = OptionParser(); + p.add_option('-i', '--index', action="store_true", help="prints out index") + + options, args = p.parse_args() + + if len(args) < 1: + sys.exit('No input file... Aborting.') + try: + fp = open_file(args[0]) + except: + sys.exit("Can't open file " + args[0] + ". Aborting.") + + try: + data = json.loads(fp.read()) + except: + e = " Error loading data from" + sys.argv[1] + ". Aborting.\n" + if sdata: + e += "Traceback: " + sdata1 + sys.exit(e) + finally: + fp.close() + + out = refactor(data) + + if options.index: + for e in out.keys(): + print '> ' + e + ' - ' + out[e]['title'] + ' ' + else: + print json.dumps(out, sort_keys=True, indent=2, separators=(',', ': ')) + + + diff --git a/rrref.sh b/rrref.sh index f48915a..9ee7599 100755 --- a/rrref.sh +++ b/rrref.sh @@ -52,7 +52,7 @@ if [[ -z "$REF" ]]; then exit; fi -node $BIBLIOGRAPHE_PATH/refactorbib.js --data $BIB > tmpbib.json +./parse/refactorbib.py $BIB > tmpbib.json REFERENCE=$(node $BIBLIOGRAPHE_PATH/generatebib.js --data tmpbib.json --items [\"$REF\"] --output $OUT) echo $REFERENCE rm tmpbib.json