port the script into python

port the script into python. The initial creation of it in node.js was just an exercise :)