58 lines
1.6 KiB
Python
58 lines
1.6 KiB
Python
import requests
|
|
from django.conf import settings
|
|
|
|
|
|
def full_testing(url_website):
|
|
status = "unknown"
|
|
|
|
#step 1 : test without VPN
|
|
status = test_website(url_website)
|
|
|
|
if status == 200:
|
|
result = "REACHABLE"
|
|
else:
|
|
#step 2 : test with VPN
|
|
status = test_website(url_website,bool_proxy=True)
|
|
if status != 200:
|
|
result = "UNREACHABLE"
|
|
else:
|
|
result = "VPN REQUIRED"
|
|
|
|
return status,result
|
|
|
|
|
|
def test_website(url_website,bool_proxy=False):
|
|
try:
|
|
if bool_proxy:
|
|
status = requests.get(url_website,proxies=settings.PROXIES).status_code
|
|
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
|
|
|
|
|
|
def randomEpisode(seasonInformation):
|
|
return 0,0
|
|
|
|
def followingEpisode(season,episode,seasonInformation,maximum_number_seasons):
|
|
lastEpisode = False
|
|
#check if the episode is the last one of the season
|
|
if (episode < seasonInformation[season-1]['episodes']):
|
|
#the current episode is not the last one of the season
|
|
episode += 1
|
|
|
|
#check if the season is the last one
|
|
elif((season+1) < maximum_number_seasons):
|
|
season += 1
|
|
episode = 1
|
|
else:
|
|
print("You watched the last episode of the serie")
|
|
lastEpisode = True
|
|
return season,episode,lastEpisode |