initial conversion of vbscript to python. Totally untested