typst_hlm / md5.py
fasdfsa's picture
rm m5 p3
4935ca9
Raw
History Blame Contribute Delete
873 Bytes
import hashlib
def md5(pth):
hash_md5 = hashlib.md5()
with open(pth, "rb") as f:
for chunk in iter(lambda: f.read(4096), b""):
hash_md5.update(chunk)
return hash_md5.hexdigest()
if __name__ == '__main__':
import glob
import os
import json
webps = glob.glob('data/**\out2\*.webp', recursive=True)
m5s = {}
for i, pth_img in enumerate(webps):
pth_md5 = pth_img.replace('.webp', '.md5')
m5 = md5(pth_img)
# base = os.path.basename(pth_img)
# with open(pth_md5, "w") as fp:
# fp.write(m5)
# if os.path.exists(pth_md5):
# os.remove(pth_md5)
m5s[m5] = pth_img.replace('\\', '/')
print(pth_img, m5, f"{i+1} / {len(webps)}")
with open('data/md5.json', "w") as fp:
json.dump(m5s, fp, indent=4, ensure_ascii=False)
pass