#!/bin/bash # Define the repository and branch REPO_URL="https://github.com/UnseenSeven/GEMFINDER.git" BRANCH="main" APP_DIR="~/ai-dreams-x" # Function to update the app.py file to remove the deprecated import function fix_imports() { # Navigate to the app directory cd $APP_DIR # Ensure the correct import sed -i 's/from werkzeug.urls import url_quote/from urllib.parse import quote as url_quote/' app.py # Stage and commit the changes git add app.py git commit -m "Remove deprecated Werkzeug import and use urllib.parse.quote" git push origin $BRANCH } # Function to deploy the application function deploy_app() { cd $APP_DIR # Force a new deployment by making a dummy change touch deploy_trigger.txt git add deploy_trigger.txt git commit -m "Trigger redeployment" git push origin $BRANCH } # Function to check deployment status function check_deployment() { # Check logs for specific errors ERROR_LOG=$(render logs ai-dreams-x | grep "ImportError: cannot import name 'url_quote'") if [ -n "$ERROR_LOG" ]; then echo "Found ImportError, attempting to fix..." return 1 else echo "No ImportError found. Checking for other issues..." return 0 fi } # Function to clean and redeploy function clean_redeploy() { # Clean and reinstall dependencies rm -rf .venv python3 -m venv .venv source .venv/bin/activate pip install -r requirements.txt # Run the deployment deploy_app } # Main loop while true; do # Pull latest changes git pull origin $BRANCH # Fix imports fix_imports # Deploy the application deploy_app # Wait for a few seconds to let deployment finish sleep 60 # Check deployment status check_deployment DEPLOY_STATUS=$? if [ $DEPLOY_STATUS -eq 0 ]; then echo "Deployment successful!" break else echo "Deployment failed. Retrying..." clean_redeploy fi # Wait a bit before retrying sleep 30 done