Tidy code for building list of examples
This commit is contained in:
parent
479dc864fd
commit
ba56274022
38
cmdline.py
38
cmdline.py
|
@ -47,6 +47,7 @@ def search_count_with_link(q: str) -> int:
|
||||||
|
|
||||||
|
|
||||||
def parse_contribs() -> list[tuple[str, int]]:
|
def parse_contribs() -> list[tuple[str, int]]:
|
||||||
|
"""Parse user contributions."""
|
||||||
re_comment = re.compile(r"^link \[\[(.*)\]\] using")
|
re_comment = re.compile(r"^link \[\[(.*)\]\] using")
|
||||||
|
|
||||||
links: collections.Counter[str] = collections.Counter()
|
links: collections.Counter[str] = collections.Counter()
|
||||||
|
@ -70,12 +71,12 @@ def parse_contribs() -> list[tuple[str, int]]:
|
||||||
return links.most_common(200)
|
return links.most_common(200)
|
||||||
|
|
||||||
|
|
||||||
with open("examples") as f:
|
def main() -> None:
|
||||||
|
with open("examples") as f:
|
||||||
seen = {json.loads(line)["title"] for line in f}
|
seen = {json.loads(line)["title"] for line in f}
|
||||||
|
|
||||||
|
out = open("examples", "a")
|
||||||
out = open("examples", "a")
|
for from_title, num in parse_contribs():
|
||||||
for from_title, num in parse_contribs():
|
|
||||||
if from_title in seen:
|
if from_title in seen:
|
||||||
continue
|
continue
|
||||||
count = search_count(from_title)
|
count = search_count(from_title)
|
||||||
|
@ -91,24 +92,27 @@ for from_title, num in parse_contribs():
|
||||||
)
|
)
|
||||||
out.flush()
|
out.flush()
|
||||||
time.sleep(0.1)
|
time.sleep(0.1)
|
||||||
out.close()
|
out.close()
|
||||||
|
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
|
|
||||||
|
count = search_count(from_title)
|
||||||
|
count_with_link = search_count_with_link(from_title)
|
||||||
|
ratio = float(count_with_link) / float(count)
|
||||||
|
|
||||||
count = search_count(from_title)
|
print(count, count_with_link, f"{ratio:.1%}")
|
||||||
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)
|
||||||
|
|
||||||
sys.exit(0)
|
totalhits, search_hits = search_no_link(from_title)
|
||||||
|
|
||||||
totalhits, search_hits = search_no_link(from_title)
|
for hit in search_hits:
|
||||||
|
|
||||||
for hit in search_hits:
|
|
||||||
print(" ", hit)
|
print(" ", hit)
|
||||||
print(count, count_with_link, f"{ratio:.1%}", totalhits, len(search_hits))
|
print(count, count_with_link, f"{ratio:.1%}", totalhits, len(search_hits))
|
||||||
|
|
||||||
# ret = core.do_search(from_title)
|
# ret = core.do_search(from_title)
|
||||||
# print(ret)
|
# print(ret)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
|
|
Loading…
Reference in a new issue