From 1140f26ca1d9cb022757153057ddb88560386fdc Mon Sep 17 00:00:00 2001 From: autodeploy <benoit@startinblox.com> Date: Mon, 10 Jun 2024 11:55:13 +0200 Subject: [PATCH] force: refetch --- .../commands/generate_static_content.py | 42 +++++++++---------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/djangoldp/management/commands/generate_static_content.py b/djangoldp/management/commands/generate_static_content.py index 7b553797..a668a542 100644 --- a/djangoldp/management/commands/generate_static_content.py +++ b/djangoldp/management/commands/generate_static_content.py @@ -80,28 +80,28 @@ class Command(BaseCommand): if not os.path.exists(associated_file_dir): os.makedirs(associated_file_dir) - if not os.path.exists(associated_file_path): + # if not os.path.exists(associated_file_path): # Fetch associated content - try: - response = requests.get(associated_url, timeout=request_timeout) - if response.status_code == 200: - associated_content = self.update_ids_and_fetch_associated(response.text, base_uri, output_dir, depth + 1, max_depth) - print(f"associated_file_path: {associated_file_path}") - associated_file_dir = os.path.dirname(associated_file_path) - print(f"associated_file_path: {associated_file_dir}") - if not os.path.exists(associated_file_dir): - os.makedirs(associated_file_dir) - with open(associated_file_path, 'w') as f: - f.write(associated_content) - self.stdout.write(self.style.SUCCESS(f'Successfully fetched and saved associated content for {associated_url}')) - else: - self.stdout.write(self.style.ERROR(f'Failed to fetch associated content from {associated_url}: {response.status_code}')) - except requests.exceptions.Timeout: - self.stdout.write(self.style.ERROR(f'Request to {associated_url} timed out')) - except requests.exceptions.RequestException as e: - self.stdout.write(self.style.ERROR(f'An error occurred: {e}')) - else: - self.stdout.write(self.style.SUCCESS(f'Associated file already exists for {associated_url}, skipping fetch')) + try: + response = requests.get(associated_url, timeout=request_timeout) + if response.status_code == 200: + associated_content = self.update_ids_and_fetch_associated(response.text, base_uri, output_dir, depth + 1, max_depth) + print(f"associated_file_path: {associated_file_path}") + associated_file_dir = os.path.dirname(associated_file_path) + print(f"associated_file_path: {associated_file_dir}") + if not os.path.exists(associated_file_dir): + os.makedirs(associated_file_dir) + with open(associated_file_path, 'w') as f: + f.write(associated_content) + self.stdout.write(self.style.SUCCESS(f'Successfully fetched and saved associated content for {associated_url}')) + else: + self.stdout.write(self.style.ERROR(f'Failed to fetch associated content from {associated_url}: {response.status_code}')) + except requests.exceptions.Timeout: + self.stdout.write(self.style.ERROR(f'Request to {associated_url} timed out')) + except requests.exceptions.RequestException as e: + self.stdout.write(self.style.ERROR(f'An error occurred: {e}')) + # else: + # self.stdout.write(self.style.SUCCESS(f'Associated file already exists for {associated_url}, skipping fetch')) for key, value in item.items(): if isinstance(value, dict): -- GitLab