Python port of rmate script