I need to Convert my Ruby code to Python!

Hi everybody

I have a big problem and unfortunately i don’t have enough time for
that.

I have a Ruby code that is in attachment and i need to change it to
Python.
Could anybody help me? its very important for me.