Datasets:
File size: 2,606 Bytes
6bf7ef0 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
import multiprocessing
import pathlib
import orjson
qp = multiprocessing.Queue()
# def processor_worker():
# while True:
# data = qp.get()
# if data is None:
# break
# def main():
# workers = 12
# with ProcessPoolExecutor(max_workers=workers) as pool:
# pool.as
# pass
bare_root = pathlib.Path("gutenberg")
idx_nums = [str(i) for i in range(0, 10)]
def iterative_folders(root: pathlib.Path):
files = []
for item in root.iterdir():
if item.is_dir():
if len(item.stem) == 1 and item.stem[0] in idx_nums:
files.extend(iterative_folders(item))
continue
# print(item)
if ".txt" not in item.suffix.lower():
html = item / f"{item.stem}-h"
if html.is_dir() and list(html.glob("*.htm")):
# print(html)
# print("htm",html)
files.append([html, "html"])
elif (item / f"{item.stem}.txt").exists():
# print("txt", item / f"{item.stem}.txt")
files.append([html, "txt"])
elif (item / f"{item.stem}-8.txt").exists():
# print("txt-8 (fb)", item / f"{item.stem}.txt")
files.append([html, "txt-8"])
elif (item / f"{item.stem}-0.txt").exists():
# print("txt-0 (fb)", item / f"{item.stem}.txt")
files.append([html, "txt-0"])
elif (item / f"{item.stem}-t" / f"{item.stem}-t.tex").exists():
# print("txt-0 (fb)", item / f"{item.stem}.txt")
files.append([html, "tex-folder"])
elif (item / "mp3").exists():
files.append([html, "audiobook-mp3"])
# print("mp3", item / f"{item.stem}.txt")
elif (item / "ogg").exists():
files.append([html, "audiobook-ogg-fb"])
pass
# print("mp3", item / f"{item.stem}.txt")
elif (item / "m4b").exists():
files.append([html, "audiobook-m4b-fb"])
pass
# print("mp3", item / f"{item.stem}.txt")
else:
files.append([item, "unk"])
print("????", item)
else:
continue
# if not has_html:
# pass
# print(item)
return files
z = []
for rd in idx_nums:
z.extend(iterative_folders(bare_root / rd))
for idx, item in enumerate(z):
z[idx] = [str(item[0]), item[1]]
pathlib.Path("index.json").write_bytes(orjson.dumps(z, option=orjson.OPT_INDENT_2))
|