Move md5it to own repo

This commit is contained in:
TKE
2021-01-14 12:19:28 +01:00
parent 214479a86a
commit 49d22d61ab

View File

@@ -1,34 +0,0 @@
#!/usr/bin/env python3
import os
import hashlib
import magic
extensions={
"message_rfc822":"eml",
"application_x-7z-compressed":"7z",
"text_html":"html",
"image_jpeg":"jpg",
"text_plain":"txt",
"application_pdf":"pdf"
}
def get_md5(filename):
md5=hashlib.md5()
with open(f,'rb') as fd:
fb=fd.read(BLOCKSIZE)
while len(fb)>0:
md5.update(fb)
fb=fd.read(BLOCKSIZE)
return md5.hexdigest()
def get_magic(filename):
magic_string=magic.from_file(filename, mime=True)
magic_string=magic_string.replace("/","_")
if magic_string in extensions:
magic_string=extensions[magic_string]
return magic_string
BLOCKSIZE=65536
files = [f for f in os.listdir('.') if os.path.isfile(f)]
for f in files:
os.rename(f,get_md5(f)+"."+get_magic(f))