From 12078b14395c88b2ea55ea3a81f8885da1d04f31 Mon Sep 17 00:00:00 2001 From: pierregeeraert Date: Wed, 5 Aug 2026 14:05:59 +0100 Subject: [PATCH] global settings and work on test website --- django_code/apps/streaming/utils.py | 22 ++++++++++++++++++++++ django_code/core/settings.py | 21 +++++++++++++++++++++ 2 files changed, 43 insertions(+) diff --git a/django_code/apps/streaming/utils.py b/django_code/apps/streaming/utils.py index e69de29..2727e64 100644 --- a/django_code/apps/streaming/utils.py +++ b/django_code/apps/streaming/utils.py @@ -0,0 +1,22 @@ +import requests +from django.conf import settings +import sys + + + + +def test_website(url_website,bool_proxy=False): + try: + if bool_proxy: + status = requests.get(url_website,proxies=settings.PROXIES) + else: + status = requests.get(url_website).status_code + + except requests.exceptions.ConnectionError: + status = "ConnectionError" + + #identify the exception name + except Exception as err: + print(f"{type(err).__name__} was raised: {err}") + status = "exception not targeted" + return status \ No newline at end of file diff --git a/django_code/core/settings.py b/django_code/core/settings.py index a1d45b5..7ff2b56 100644 --- a/django_code/core/settings.py +++ b/django_code/core/settings.py @@ -11,6 +11,7 @@ https://docs.djangoproject.com/en/4.2/ref/settings/ """ import os from pathlib import Path +from urllib import request as urllib_request # Build paths inside the project like this: BASE_DIR / 'subdir'. BASE_DIR = Path(__file__).resolve().parent.parent @@ -223,3 +224,23 @@ CELERY_IMPORTS = [ 'apps.random_simpsons.utils' # Add other app tasks here if needed ] + + + +########################################################################################### +# +# Custom settings +# +########################################################################################### + + +PROXY_URL = 'http://gluetun-svc.gluetun.svc:8888' +PROXY = urllib_request.ProxyHandler({ + 'http': PROXY_URL, + 'https': PROXY_URL # Add the handler for HTTPS +}) + +PROXIES = { + "http" : PROXY_URL, + "https" : PROXY_URL +}