Renew certificates with acme_tiny for let's encrypt

def acme_renew_certificates():
    '''
        Renew certificates with acme_tiny for let's encrypt
    '''

    for csr in glob(os.path.join(CERTIFICATES_PATH, '*.csr')):
        common_name = os.path.basename(csr)
        common_name = os.path.splitext(common_name)[0]

        certificate_path = "{}.crt".format(common_name)
        certificate_path = os.path.join(CERTIFICATES_PATH, certificate_path)

        with open(certificate_path) as file:
            crt = OpenSSL.crypto.load_certificate(OpenSSL.crypto.FILETYPE_PEM,
                                                    file.read())
            expiration = crt.get_notAfter()
            expiration = _parse_asn1_generalized_date(expiration)
            remaining = expiration - datetime.utcnow()
            if remaining > timedelta(days=30):
                print "No need to renew {} ({})".format(certificate_path, remaining)
                continue
            print "Renewing {} ({})".format(certificate_path, remaining)

        certificate_request_path = "{}.csr".format(common_name)
        certificate_request_path = os.path.join(CERTIFICATES_PATH,
                                                certificate_request_path)

        signed_cert = "{}-signed.crt".format(common_name)
        signed_cert = os.path.join(CERTIFICATES_PATH,
                                    signed_cert)

        _internal_sign_certificate(certificate_path, certificate_request_path,
                                    signed_cert)