diff --git a/create_tmpbib.py b/create_tmpbib.py index f75efef..7aa29e6 100644 --- a/create_tmpbib.py +++ b/create_tmpbib.py @@ -32,7 +32,7 @@ def write_report(report): print("Number of unique citekeys in the publication: {}".format(report["found_citekeys"])) if len(report["unmatched"]) > 0: - print("{} {} could not be matched to entries from the formatted bibliography.".format(len(report["unmatched"]), libeoaconvert.plural(len(report["unmatched"]), "citekey"))) + print("{} {} found in the publication could not be matched to entries from the formatted bibliography.".format(len(report["unmatched"]), libeoaconvert.plural(len(report["unmatched"]), "citekey"))) for item in report["unmatched"]: print(' '*4, item) else: @@ -161,38 +161,48 @@ def main(): count = 1 if len(candidates) == 1: sys.stdout.write("Found only one match: {}\n".format(citekey_dict[candidates[0]])) - yesno = input("""Assign that entry to the found citekey? [Y/n]""") - print("input", yesno) + yesno = input("""Assign that entry to the found citekey? [Y/n] """) if yesno.lower() in ["y", ""]: annotation = citekey_dict[candidates[0]] removed_item = citekey_dict.pop(candidates[0]) - print("RI", removed_item) removed_items.append(removed_item) + entry_keyword = "FIXME" else: - annotation = "" + unmatched_citekeys.append(e.rstrip()) + entry_keyword = "FILLMEIN" + annotation = "No candidate found in formatted bibliography" elif len(candidates) > 1: sys.stdout.write("Found \n") for i in candidates: sys.stdout.write("%s. %s" % (count, citekey_dict[i])) count += 1 - answer = input("""Does one of those (1 - %s) fit?\nTo abort, just press Enter: """ % (count - 1, )) - if answer: + answer = input("""Does one of those (1 - %s) fit?\nTo abort, press 'n': """ % (count - 1, )) + print("The answer is", answer) + if answer.lower() == 'n': + annotation = "No candidate found in formatted bibliography" + entry_keyword = "FILLMEIN" + elif int(answer) in range(1, count): chosen_citekey = candidates[int(answer) - 1 ] annotation = citekey_dict[chosen_citekey] + entry_keyword = "FIXME" removed_item = citekey_dict.pop(chosen_citekey) - print(removed_item) removed_items.append(removed_item) - else: - annotation = "" else: - sys.stdout.write("No candidate found.") + sys.stdout.write("No candidate found in formatted bibliography for citekey %s.\n" % e.rstrip()) unmatched_citekeys.append(e.rstrip()) - annotation = "" + annotation = "No candidate found in formatted bibliography" + entry_keyword = "FILLMEIN" - # logging.debug(e.rstrip()) entrydict = {} if args.keyword is not None: - entrydict["keywords"] = args.keyword + all_keywords = entry_keyword.split(", ") + if args.keyword in all_keywords: + print("keyword already in ") + continue + else: + print("option keyword") + entry_keyword = entry_keyword + ", " + args.keyword + entrydict["keywords"] = entry_keyword entrydict["ENTRYTYPE"] = "book" entrydict["title"] = "Faketitle" entrydict["comments"] = annotation.rstrip() @@ -210,6 +220,10 @@ def main(): report["formatted_removed"] = removed_items report["formatted_notremoved"] = [x for x in citekey_dict.values() if not x in removed_items] + formatted_not_found_path = TMP_DIR + os.path.sep + "unassigned_formatted_entries.txt" + with open(formatted_not_found_path, 'w') as unassigned: + unassigned.write("\n".join([x for x in citekey_dict.values() if not x in removed_items])) + bibfile_path = TMP_DIR + os.path.sep + "prelim.bib" write_report(report)