From 993aa3ee3d46bf7b3b10bb02fdb6951034e0c629 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Pasquier <contact@jbpasquier.eu> Date: Fri, 21 Jun 2024 18:55:08 +0200 Subject: [PATCH] fix: encoding --- .../management/commands/generate_static_content.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/djangoldp/management/commands/generate_static_content.py b/djangoldp/management/commands/generate_static_content.py index 45648582..b7d64d11 100644 --- a/djangoldp/management/commands/generate_static_content.py +++ b/djangoldp/management/commands/generate_static_content.py @@ -1,10 +1,11 @@ +import json import os +from urllib.parse import urlparse, urlunparse + import requests -import json -from django.core.management.base import BaseCommand -from django.conf import settings from django.apps import apps -from urllib.parse import urlparse, urlunparse +from django.conf import settings +from django.core.management.base import BaseCommand base_uri = getattr(settings, 'BASE_URL', '') max_depth = getattr(settings, 'MAX_RECURSION_DEPTH', 5) @@ -45,7 +46,7 @@ class Command(BaseCommand): file_path = os.path.join(output_dir, f'{filename}.jsonld') print(f"Output file_path: {file_path}") - with open(file_path, 'w') as f: + with open(file_path, 'w', encoding='utf-8') as f: f.write(content) self.stdout.write(self.style.SUCCESS(f'Successfully fetched and saved content for {model._meta.model_name} from {url}')) regenerated_urls.append(url) @@ -96,7 +97,7 @@ class Command(BaseCommand): if not os.path.exists(associated_file_dir): os.makedirs(associated_file_dir) - with open(associated_file_path, 'w') as f: + with open(associated_file_path, 'w', encoding='utf-8') as f: f.write(associated_content) regenerated_urls.append(associated_url) self.stdout.write(self.style.SUCCESS(f'Successfully fetched and saved associated content for {associated_url}')) -- GitLab