diff --git a/cmdline.py b/cmdline.py index 1d1de7c..1b2edb1 100755 --- a/cmdline.py +++ b/cmdline.py @@ -47,6 +47,7 @@ def search_count_with_link(q: str) -> int: def parse_contribs() -> list[tuple[str, int]]: + """Parse user contributions.""" re_comment = re.compile(r"^link \[\[(.*)\]\] using") links: collections.Counter[str] = collections.Counter() @@ -70,45 +71,48 @@ def parse_contribs() -> list[tuple[str, int]]: return links.most_common(200) -with open("examples") as f: - seen = {json.loads(line)["title"] for line in f} +def main() -> None: + with open("examples") as f: + seen = {json.loads(line)["title"] for line in f} + out = open("examples", "a") + for from_title, num in parse_contribs(): + if from_title in seen: + continue + count = search_count(from_title) + count_with_link = search_count_with_link(from_title) + ratio = float(count_with_link) / float(count) + + print(from_title, count, count_with_link, f"{ratio:.1%}") + print( + json.dumps( + {"title": from_title, "total": count, "with_links": count_with_link} + ), + file=out, + ) + out.flush() + time.sleep(0.1) + out.close() + + sys.exit(0) -out = open("examples", "a") -for from_title, num in parse_contribs(): - if from_title in seen: - continue count = search_count(from_title) count_with_link = search_count_with_link(from_title) ratio = float(count_with_link) / float(count) - print(from_title, count, count_with_link, f"{ratio:.1%}") - print( - json.dumps( - {"title": from_title, "total": count, "with_links": count_with_link} - ), - file=out, - ) - out.flush() - time.sleep(0.1) -out.close() + print(count, count_with_link, f"{ratio:.1%}") -sys.exit(0) + sys.exit(0) + + totalhits, search_hits = search_no_link(from_title) + + for hit in search_hits: + print(" ", hit) + print(count, count_with_link, f"{ratio:.1%}", totalhits, len(search_hits)) + + # ret = core.do_search(from_title) + # print(ret) -count = search_count(from_title) -count_with_link = search_count_with_link(from_title) -ratio = float(count_with_link) / float(count) - -print(count, count_with_link, f"{ratio:.1%}") - -sys.exit(0) - -totalhits, search_hits = search_no_link(from_title) - -for hit in search_hits: - print(" ", hit) -print(count, count_with_link, f"{ratio:.1%}", totalhits, len(search_hits)) - -# ret = core.do_search(from_title) -# print(ret) +if __name__ == "__main__": + main()