From 153303dc564084d480c6f6806625216b4d3a4019 Mon Sep 17 00:00:00 2001 From: TKE Date: Thu, 14 Jan 2021 12:19:28 +0100 Subject: [PATCH] Move md5it to own repo --- md5it.py | 34 ---------------------------------- 1 file changed, 34 deletions(-) delete mode 100755 md5it.py diff --git a/md5it.py b/md5it.py deleted file mode 100755 index de04cae..0000000 --- a/md5it.py +++ /dev/null @@ -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))