KaraKaraWitch commited on
Commit
6bf7ef0
1 Parent(s): 149cce2

Upload scripts/gutenberg_index.py with huggingface_hub

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