-
Notifications
You must be signed in to change notification settings - Fork 2
/
update_from_hiyori
executable file
·46 lines (36 loc) · 1.34 KB
/
update_from_hiyori
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
#!/usr/bin/env python3
import sys
import os
import json
from typing import Iterator, Dict, List
from pathlib import Path
this_dir = Path(os.path.dirname(os.path.abspath(__file__)))
cache_dir = this_dir / "cache"
def read_file(p: Path) -> Iterator[int]:
for line in map(str.strip, p.read_text().splitlines()):
if line:
yield int(line)
def backfill_type(_type: str, hiyori_cache_dir: Path):
target_file: Path = cache_dir / f"{_type}_cache.json"
base: Path = hiyori_cache_dir / f"{_type}_"
updated_cache: Dict[str, List[int]] = {
"sfw": sorted(read_file(Path(str(base) + "sfw.txt"))),
"nsfw": sorted(read_file(Path(str(base) + "nsfw.txt"))),
}
# sanity checks
assert len(updated_cache["sfw"]) > 10000
assert len(updated_cache["nsfw"]) > 1000
with target_file.open("w") as f:
json.dump(updated_cache, f, indent=4)
print(f"Updated {_type} cache file from {base}* to {target_file}")
def main():
if len(sys.argv) <= 1:
print("Must provide Hiyori txt cache dir as first argument")
sys.exit(1)
hiyori_cache_dir = Path(sys.argv[1]).absolute()
assert hiyori_cache_dir.exists()
assert (hiyori_cache_dir / "anime_sfw.txt").exists()
backfill_type("anime", hiyori_cache_dir)
backfill_type("manga", hiyori_cache_dir)
if __name__ == "__main__":
main()