import subprocess
import logging

try:
	result = subprocess.run(['sudo', 'certbot', 'certificates'], capture_output=True, text=True, check=True)
	print("Certbot output:", result.stdout)
except subprocess.CalledProcessError as e:
	print("Error running Certbot:", e.stderr)
	print("Stdout:", result.stderr)

for i in result:
    print(i)


'''
# Configure logging
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')

def renew_certbot_certificates():
    """
    Attempts to renew Certbot SSL certificates.
    """
    try:
        logging.info("Attempting to renew Certbot certificates...")
        # Execute the certbot renew command
        # Use --nginx or --apache if you have specific web server plugins
        # Use --quiet to suppress verbose output
        result = subprocess.run(
            ['sudo', 'certbot', 'renew', '--quiet'],
            capture_output=True,
            text=True,
            check=True
        )
        logging.info(f"Certbot renewal successful:\n{result.stdout}")
    except subprocess.CalledProcessError as e:
        logging.error(f"Certbot renewal failed:\n{e.stderr}")
    except FileNotFoundError:
        logging.error("Certbot command not found. Ensure Certbot is installed and in your PATH.")
    except Exception as e:
        logging.error(f"An unexpected error occurred during renewal: {e}")

if __name__ == "__main__":
    renew_certbot_certificates()

'''



