diff --git a/lexipython.py b/lexipython.py index 43b0ba8..5fe3790 100644 --- a/lexipython.py +++ b/lexipython.py @@ -31,10 +31,6 @@ def titlestrip(s): if s.startswith("A "): return s[2:] return s -def cmp_title(x, y): - """Compares strings in titular order, ignoring prefixed articles.""" - return cmp(titlestrip(x), titlestrip(y)) - def link_formatter(written_articles): """ Creates a lambda that formats citation links and handles the phantom class. @@ -137,19 +133,19 @@ def parse_lex_from_directory(directory): Output: a list of parsed lex file structures """ lexes = [] - print "Reading lex files from", directory + print("Reading lex files from", directory) for filename in os.listdir(directory): path = directory + filename # Read only .lex files if path[-4:] == ".lex": - print " Parsing", path, + print(" Parsing", path, end=" ") with open(path) as lex_file: lex_raw = lex_file.read() parsed_lex = parse_lex(lex_raw) if "error" in parsed_lex: - print "ERROR:", parsed_lex["error"] + print("ERROR:", parsed_lex["error"]) else: - print "SUCCESS:", parsed_lex["title"] + print("SUCCESS:", parsed_lex["title"]) lexes.append(parsed_lex) return lexes @@ -197,7 +193,7 @@ def make_cite_map(lex_list): cite_map = {} for lex in lex_list: cited_titles = [cite_tuple[1] for format_id, cite_tuple in lex["citations"].items()] - cite_map[lex["title"]] = sorted(set(cited_titles), cmp=cmp_title) + cite_map[lex["title"]] = sorted(set(cited_titles), key=titlestrip) return cite_map def format_content(lex, format_func): @@ -225,7 +221,7 @@ def citation_lists(title, cite_map): citers = [citer_title for citer_title, cited_titles in cite_map.items() if title in cited_titles] - return cite_map[title], citers + return cite_map[title] if title in cite_map else [], citers def build_article_page(lex, cite_map, config): """ @@ -241,7 +237,9 @@ def build_article_page(lex, cite_map, config): # Build the article citeblock cites, citedby = citation_lists(lex["title"], cite_map) cites_str = " | ".join([lf(None, title, title) for title in cites]) + if len(cites_str) < 1: cites_str = "--" citedby_str = " | ".join([lf(None, title, title) for title in citedby]) + if len(citedby_str) < 1: citedby_str = "--" citeblock = ""\ "
\n"\ "

Citations: {cites}

\n"\ @@ -335,10 +333,8 @@ def build_index_page(cite_map, config): Output: the HTML of the index page """ # Count up all the titles - titles = sorted( - (set(cite_map.keys()) | - set([title for cited_titles in cite_map.values() for title in cited_titles])) - , cmp=cmp_title) + titles = set(cite_map.keys()) | set([title for cited_titles in cite_map.values() for title in cited_titles]) + titles = sorted(set(titles), key=titlestrip) content = "" if len(titles) == len(cite_map.keys()): content = "

There are {0} entries in this lexicon.

\n