Skip to content

Commit

Permalink
Clone wp post
Browse files Browse the repository at this point in the history
  • Loading branch information
leomendoza123 committed May 16, 2024
1 parent 94dac74 commit c17210a
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions wordpress-cloning-img-script.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,11 @@ def download_and_update_html(environment, wordpress_staging_username, wordpress_

# Setup authentication if not in production environment
auth = None
base_path = 'https://d3055hwma3riwo.cloudfront.net/'
if environment != "PROD":
auth = HTTPBasicAuth(wordpress_staging_username, wordpress_staging_password)
base_path = 'https://UPDATE_ME.cloudfront.net/'


# Create directory for saving images if it does not exist
if not os.path.exists(folder_path):
Expand Down Expand Up @@ -46,7 +49,7 @@ def download_and_update_html(environment, wordpress_staging_username, wordpress_
img_data.raw.decode_content = True
shutil.copyfileobj(img_data.raw, file)
# Update the src attribute to the new local path
img['src'] = os.path.join('./', local_filename)
img['src'] = os.path.join(base_path, local_filename)

# Get the srcset attribute of the image
img_srcset = img.get('srcset')
Expand All @@ -66,7 +69,7 @@ def download_and_update_html(environment, wordpress_staging_username, wordpress_
img_data.raw.decode_content = True
shutil.copyfileobj(img_data.raw, file)
# Add the new srcset item to the list
new_srcset.append(f"{os.path.join('./', local_filename)} {size}")
new_srcset.append(f"{os.path.join(base_path, local_filename)} {size}")
# Update the srcset attribute to the new local paths
img['srcset'] = ', '.join(new_srcset)

Expand Down

0 comments on commit c17210a

Please sign in to comment.