Rewrite script/upload in Python