diff --git a/eoaconvert.py b/eoaconvert.py index f6bb6d3..aed62db 100755 --- a/eoaconvert.py +++ b/eoaconvert.py @@ -1,6 +1,6 @@ #!/usr/bin/env python3 # -*- coding: utf-8; mode: python -*- -# Time-stamp: <2018-01-22 13:22:15 (kthoden)> +# Time-stamp: <2018-01-22 16:45:16 (kthoden)> # license? __version__= "1.0" @@ -21,6 +21,7 @@ import re import string import shlex +import json import subprocess import sys import shutil @@ -261,7 +262,9 @@ def createBibEntryAuthorYear(bibEntry, boolSameAuthor): if bibEntry.entrytype() == "newspaper": strBibEntry = strAuthor + " (" + bibEntry.labelyear() + bibEntry.labelyearsuffix() + "). " + bibEntry.title() + "" - return(sanitize_bibentry(strBibEntry)) + print(strBibEntry) + + return sanitize_bibentry(strBibEntry) # def createBibEntryAuthorYear ends here def createBibEntryNumeric(bibEntry): @@ -293,7 +296,7 @@ def createBibEntryNumeric(bibEntry): strBibEntry = strAuthor + " (" + bibEntry.labelyear() + bibEntry.labelyearsuffix() + ") " + bibEntry.title() + "." return strBibEntry -# def createBibEntryAuthorYear ends here +# def createBibEntryNumeric ends here def pdf_burst(input_file, tmpDir): """Split PDF file into single pages""" @@ -893,24 +896,28 @@ def cleanup(): print("-----------------------------------------------------") print("Working on Page Numbers for References") listAuxFiles = glob.glob(os.getcwd() + "/*.aux") -for strFile in listAuxFiles: - tmpFile = open(strFile, "r") - lines = tmpFile.readlines() - tmpFile.close() - for line in lines: - # hyperref makes the lines much much longer - # \newlabel{BL}{{1.1}{4}{Forschungsüberblick zur Literatur über Alvarus Thomas}{section.1.1}{}} - # \newlabel{BL}{{1.1}{4}} - matched_label = re.match(r'\\newlabel\{(.*?)\}\{\{(.*?)\}\{(.*?)\}', line) - # matchObjectLabel = re.match(r'\newlabel\{(.*?)\}', line) - if matched_label: - # matchObjectPage = re.match(r'(.*?)\}\{(\d{1,})\}\}$', line) - # if matchObjectPage: - dictPagelabels[matched_label.group(1)] = matched_label.group(3) - # parsing out information on cite works - matched_citation = re.match(r'\\abx@aux@cite{(.*?)}', line) - if matched_citation is not None: - set_citations.add(matched_citation.group(1)) +if len(listAuxFiles) == 0: + print("No aux file found. Exiting") + sys.exit(1) +else: + for strFile in listAuxFiles: + tmpFile = open(strFile, "r") + lines = tmpFile.readlines() + tmpFile.close() + for line in lines: + # hyperref makes the lines much much longer + # \newlabel{BL}{{1.1}{4}{Forschungsüberblick zur Literatur über Alvarus Thomas}{section.1.1}{}} + # \newlabel{BL}{{1.1}{4}} + matched_label = re.match(r'\\newlabel\{(.*?)\}\{\{(.*?)\}\{(.*?)\}', line) + # matchObjectLabel = re.match(r'\newlabel\{(.*?)\}', line) + if matched_label: + # matchObjectPage = re.match(r'(.*?)\}\{(\d{1,})\}\}$', line) + # if matchObjectPage: + dictPagelabels[matched_label.group(1)] = matched_label.group(3) + # parsing out information on cite works + matched_citation = re.match(r'\\abx@aux@cite{(.*?)}', line) + if matched_citation is not None: + set_citations.add(matched_citation.group(1)) print(dictPagelabels) print(set_citations) @@ -949,6 +956,20 @@ def cleanup(): HAS_BIBLIOGRAPHY = False input() +# the new solution: pandoc-citeproc +interim_bib_json_file = (options.filename) + "-bib.json" +citeproc_command = "pandoc-citeproc --bib2json %s" % bib_database + ".bib" +logging.debug(citeproc_command) +citeproc_arguments = shlex.split(citeproc_command) +citeproc_process = subprocess.Popen(citeproc_arguments, stdout=subprocess.PIPE) +citeproc_json = citeproc_process.stdout.read() + +jsonObj = json.loads(citeproc_json) + +for x in jsonObj: + print(x["title"]) + +# the old solution # Copy interim .bbl-File to interim bib.tex file interim_bibtex_file = (options.filename) + "bib.tex" try: