Skip to content

Instantly share code, notes, and snippets.

@quaxsze
Last active October 10, 2023 13:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save quaxsze/790698bb08220a580cee43cce64fdfdd to your computer and use it in GitHub Desktop.
Save quaxsze/790698bb08220a580cee43cce64fdfdd to your computer and use it in GitHub Desktop.
from udata.models import Dataset
from udata.app import create_app
def migrate():
print('Processing resources.')
app = create_app()
with app.app_context():
datasets = Dataset.objects(resources__url__contains='http://static').no_cache().timeout(False)
counter = 0
for dataset in datasets:
for resource in dataset.resources:
if resource.url.startswith('http://static'):
resource.url = resource.url.replace('http://', 'https://')
counter += 1
try:
dataset.save()
except Exception as e:
print(e)
pass
print(f'Completed migration on {counter} resources.')
if __name__ == "__main__":
migrate()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment