last commit for this tag

This commit is contained in:
gauthiier 2016-03-14 15:47:30 +01:00
parent a43c4fa698
commit 5e4beb6b71
4 changed files with 67 additions and 9 deletions

View File

@ -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

View File

@ -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)

63
parse/refactorbib.py Executable file
View File

@ -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 = "<refactorbib> 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=(',', ': '))

View File

@ -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