refactor python scripts with bash function

also make them work with python3 :)