consolidate python code into bash helper function

consolidate all the python code into keyword-selected chunks in the bash helper function. check it out, it's nicer this way, with less echo, less quoting, etc.