Use framework functions for re/datetime; use 1 (compiled) regex to do all the replacing at once instead of a bunch of nested re.subs; use same (tab) indentation everywhere.