Having a ABCPlone6Website.blabla with ABCPlone6Staging.blabla, let’s say you delete some images and you want to restore them from staging website.
My method was to:
- Download the images with a script (I had the list of broken images urls) from staging website
- Save them in a folders structure like the one used in the website.
- Manually upload in production website one by one following the folders structure and the broken urls list.
The script:
import os
import requests
PREFIX = '/home/ghitabizau/work/ABCPlone6Website/temp/'
def create_folders(folders):
try:
path = PREFIX + "/".join(folders)
os.makedirs(path)
except Exception:
print("Already exists:", path)
def save_image(url):
filename = url.split('/')[-1]
download_url = url + '/@@download/image'
img_data = requests.get(download_url).content
folders = url.split('https://')[-1].split("/")[0:-1]
path = PREFIX + "/".join(folders)
with open(path + '/' + filename, 'wb') as handler:
handler.write(img_data)
print("Saved image")
urls = [
"https://ABCPlone6Staging.blabla/en/how-to-guides/how-to-download-spatial-data/how-to-use-the-shopping-cart/htg-shopping-cart-popup.png",
"https://ABCPlone6Staging.blabla/en/globe-from-space.jpg",
"https://ABCPlone6Staging.blabla/en/products/vegetation/legends/lsp/length.png",
... other 250 items ...
]
index = 0
for url in urls:
if 'legends' not in url:
continue
index += 1
folders = url.split('https://')[-1].split("/")[0:-1]
create_folders(folders)
save_image(url)
Category: Docs