Rewrite combaine-machine script in python