46 lines
1.3 KiB
Python
46 lines
1.3 KiB
Python
#!/usr/bin/env python3
|
|
# -*- encoding: utf-8 -*-
|
|
|
|
import json
|
|
import subprocess
|
|
from concurrent.futures import ProcessPoolExecutor as PoolExecutor
|
|
from pathlib import Path
|
|
from typing import Dict, Union
|
|
import hashlib
|
|
import sys
|
|
from io import BytesIO
|
|
|
|
import PIL.Image
|
|
|
|
import reddit_imgs.hashit
|
|
|
|
from .hashit import hash2pathsegments
|
|
from .system.table_fmt import table_fmt
|
|
|
|
EXTS_OKAY = ('png', 'jpg')
|
|
|
|
def main():
|
|
image_hashes_extensions_path = Path('i_he.json')
|
|
if not image_hashes_extensions_path.exists():
|
|
print("Executing prerrequisite...")
|
|
reddit_imgs.hashit.main()
|
|
image_hashes_extensions = json.loads(
|
|
image_hashes_extensions_path.read_text()
|
|
)
|
|
used_extensions = {i: 0 for i in set(image_hashes_extensions.values())}
|
|
for e in image_hashes_extensions.values():
|
|
used_extensions[e] += 1
|
|
image_hashed_path = Path('i_h')
|
|
image_hashed_normalized_path = Path('i_h_n')
|
|
image_hashed_normalized_path.mkdir(parents=True, exist_ok=True)
|
|
print(table_fmt(
|
|
['ext', 'hashes'],
|
|
sorted(used_extensions.items(), key=lambda t: (t[1], t[0]))+[
|
|
('total', sum(used_extensions.values())),
|
|
],
|
|
'Extensions',
|
|
alignment='^>',
|
|
divide_last_line=True,
|
|
))
|
|
converted_path = Path('i_h_n.json')
|
|
converted = dict() |