diff --git a/web-app/django/VIM/apps/instruments/management/commands/import_languages.py b/web-app/django/VIM/apps/instruments/management/commands/import_languages.py index 19219a0b..982022b8 100644 --- a/web-app/django/VIM/apps/instruments/management/commands/import_languages.py +++ b/web-app/django/VIM/apps/instruments/management/commands/import_languages.py @@ -141,20 +141,25 @@ def get_language_directions_from_sparql(url: str): } GROUP BY ?code """ - response = requests.get( - url, params={"query": query, "format": "json"}, headers=HEADERS, timeout=200 - ) - data = response.json() - - directions = {} - for item in data.get("results", {}).get("bindings", []): - code = item["code"]["value"].lower() - direction_label = item["direction"]["value"] - if "right-to-left" in direction_label: - directions[code] = "rtl" - else: - directions[code] = "ltr" - return directions + try: + response = requests.get( + url, params={"query": query, "format": "json"}, headers=HEADERS, timeout=200 + ) + response.raise_for_status() + data = response.json() + + directions = {} + for item in data.get("results", {}).get("bindings", []): + code = item["code"]["value"].lower() + direction_label = item["direction"]["value"] + if "right-to-left" in direction_label: + directions[code] = "rtl" + else: + directions[code] = "ltr" + return directions + except requests.RequestException as e: + print(f"Error: Failed to fetch language direction data. {e}") + return {} class Command(BaseCommand):