md5.py 1.79 KB
#!/usr/bin/python
#encoding=utf-8
import os
import io
import sys
import hashlib
import string
import subprocess

def printUsage():
    print ('''Usage: [python] md5.py <filename> <module>''')
    print ('''       module has two optional value: jp,rn''')
    print ('''       default is jp''')

def write2Clipboard(output):
    process = subprocess.Popen(
        'pbcopy', env={'LANG': 'en_US.UTF-8'}, stdin=subprocess.PIPE)
    process.communicate(output.encode('utf-8'))

def calMd5(filename, module="jp"):
    print("🍅🍅🍅🍅🍅🍅🍅🍅🍅🍅🍅🍅🍅🍅🍅🍅🍅🍅🍅🍅🍅🍅🍅🍅🍅🍅")
    if not os.path.isfile(filename):
        print("👿  file doesn't exist\t" + filename)
        return
    m0 = hashlib.md5()
    file = io.FileIO(filename,'r')
    bytes = file.read(8096)
    while(bytes != b''):
        m0.update(bytes)
        bytes = file.read(8096)
    file.close()

    md5value = m0.hexdigest()
    print("😇  file\t\t\t" + filename)
    print("😌  file md5 value\t" + md5value)

    suffixes = "yohopatch2016"
    if module == 'rn':
        suffixes = "yohorn2016"

    m1 = hashlib.md5()
    source = md5value + suffixes
    m1.update(source.encode("utf8"))
    sourceMd5value = m1.hexdigest()
    print("😏  string\t\t" + source)
    print("😋  string md5 value\t" + sourceMd5value)

    write2Clipboard(sourceMd5value)
    print("😀  the value already write to your clipboard\t")
    print("🚀  🚁  ✈️ now you can use command + v to paste it!!!\t")
    print("🍊🍊🍊🍊🍊🍊🍊🍊🍊🍊🍊🍊🍊🍊🍊🍊🍊🍊🍊🍊🍊🍊🍊🍊🍊🍊🍊")

def main():
    if(sys.argv.__len__() == 2):
        calMd5(sys.argv[1])
    elif(sys.argv.__len__() == 3):
        calMd5(sys.argv[1], sys.argv[2])
    else:
        printUsage()

main()