Refactor python scripts

led `contrib/python` in order. If something is unclear or you have ideas how to make it a better, i will fix it.