Jurnal

keep calm and conquer the world

Menu
  • Home
  • Plimbări
  • Echipamente
  • Recomand
  • Contact
Menu

Restore deleted images Plone 6

Posted on 26.03.2025 by GhitaB

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:

  1. Download the images with a script (I had the list of broken images urls) from staging website
  2. Save them in a folders structure like the one used in the website.
  3. 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)
Tags: docs, plone, web development
Category: Docs

Post navigation

← EORI (poveste românească)
O comandă cu tâlc →

Archives

  • June 2025 (2)
  • May 2025 (10)
  • April 2025 (3)
  • March 2025 (19)
  • February 2025 (20)
  • January 2025 (33)
  • December 2024 (8)
  • November 2024 (4)
  • October 2024 (8)
  • September 2024 (4)
  • August 2024 (9)
  • July 2024 (21)
  • June 2024 (17)
  • May 2024 (13)
  • April 2024 (1)
  • March 2024 (7)
  • February 2024 (15)
  • January 2024 (24)
  • December 2023 (11)
  • November 2023 (53)
  • October 2023 (17)
  • September 2023 (20)
  • August 2023 (40)
  • July 2023 (39)
  • June 2023 (38)

Categories

  • 27 (4)
  • Acasă (64)
  • Amintiri (13)
  • Creștine (33)
  • Desen (8)
  • Design (1)
  • Docs (53)
  • Duldy & Țâcă (5)
  • Fotografie (42)
  • Gânduri (105)
  • Grădină (10)
  • Interesant (14)
  • Istorie (4)
  • Jurnal (168)
  • Limba română (8)
  • Mașină (2)
  • Muzică (46)
  • Personal (104)
  • Plimbări (24)
  • Programare (25)
  • Sport (12)
  • Știri (37)
  • Vegan (16)

Tags

2 mese pe zi (5) acasă (57) am auzit ceva nou (5) amintiri (8) am scris asta (7) biblice (11) Bihor (15) biserică (5) creștine (56) câine (13) câinele e prietenul omului (13) desen (8) docs (48) fotografie (45) funny (63) grădină (10) gânduri (123) interesant (8) istorie (7) jurnal (204) jurnal sportiv (11) Krita (5) limba română (10) momente (194) muzică (48) muzică preluată (28) natură (6) Padiș (11) personal (146) plimbare (22) plone (27) povești (7) programare (27) recomand (8) rețete vegane (10) România (29) Rusia (5) sketchbook (5) solutions (30) spam (5) sport (6) vegan (17) versuri (6) web development (17) știri (21)

RSS Feed Subscribe
© 2025 Jurnal | Powered by Minimalist Blog WordPress Theme