Update django_code/apps/streaming/utils.py #39
@@ -1,67 +1,67 @@
|
|||||||
import requests
|
import requests
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from apps.betaserie.utils import betaserieUtils
|
from apps.betaserie.utils import betaserieUtils
|
||||||
import random
|
import random
|
||||||
|
|
||||||
def full_testing(url_website):
|
def full_testing(url_website):
|
||||||
status = "unknown"
|
status = "unknown"
|
||||||
|
|
||||||
#step 1 : test without VPN
|
#step 1 : test without VPN
|
||||||
status = test_website(url_website)
|
status = test_website(url_website)
|
||||||
|
|
||||||
if status == 200:
|
if status == 200:
|
||||||
result = "REACHABLE"
|
result = "REACHABLE"
|
||||||
else:
|
else:
|
||||||
#step 2 : test with VPN
|
#step 2 : test with VPN
|
||||||
status = test_website(url_website,bool_proxy=True)
|
status = test_website(url_website,bool_proxy=True)
|
||||||
if status != 200:
|
if status != 200:
|
||||||
result = "UNREACHABLE"
|
result = "UNREACHABLE"
|
||||||
else:
|
else:
|
||||||
result = "VPN REQUIRED"
|
result = "VPN REQUIRED"
|
||||||
|
|
||||||
return status,result
|
return status,result
|
||||||
|
|
||||||
|
|
||||||
def test_website(url_website,bool_proxy=False):
|
def test_website(url_website,bool_proxy=False):
|
||||||
try:
|
try:
|
||||||
if bool_proxy:
|
if bool_proxy:
|
||||||
status = requests.get(url_website,proxies=settings.PROXIES).status_code
|
status = requests.get(url_website,proxies=settings.PROXIES).status_code
|
||||||
else:
|
else:
|
||||||
status = requests.get(url_website).status_code
|
status = requests.get(url_website).status_code
|
||||||
|
|
||||||
except requests.exceptions.ConnectionError:
|
except requests.exceptions.ConnectionError:
|
||||||
status = "ConnectionError"
|
status = "ConnectionError"
|
||||||
|
|
||||||
#identify the exception name
|
#identify the exception name
|
||||||
except Exception as err:
|
except Exception as err:
|
||||||
print(f"{type(err).__name__} was raised: {err}")
|
print(f"{type(err).__name__} was raised: {err}")
|
||||||
status = "exception not targeted"
|
status = "exception not targeted"
|
||||||
return status
|
return status
|
||||||
|
|
||||||
|
|
||||||
def randomEpisode(seasonInformation,maximum_number_of_seasons):
|
def randomEpisode(seasonInformation,maximum_number_of_seasons):
|
||||||
random_season = random.randint(1, maximum_number_of_seasons)
|
random_season = random.randint(1, maximum_number_of_seasons)
|
||||||
print("random season: " + str(random_season))
|
print("random season: " + str(random_season))
|
||||||
|
|
||||||
maximum_number_of_episodes = seasonInformation[random_season-1]['episodes']
|
maximum_number_of_episodes = seasonInformation[random_season-1]['episodes']
|
||||||
|
|
||||||
random_episode = random.randint(1, maximum_number_of_episodes)
|
random_episode = random.randint(1, maximum_number_of_episodes)
|
||||||
print("random episode: " + str(random_episode))
|
print("random episode: " + str(random_episode))
|
||||||
|
|
||||||
return random_season,random_episode
|
return random_season,random_episode
|
||||||
|
|
||||||
def followingEpisode(season,episode,seasonInformation,maximum_number_seasons):
|
def followingEpisode(season,episode,seasonInformation,maximum_number_seasons):
|
||||||
lastEpisode = False
|
lastEpisode = False
|
||||||
#check if the episode is the last one of the season
|
#check if the episode is the last one of the season
|
||||||
if (episode < seasonInformation[season-1]['episodes']):
|
if (episode < seasonInformation[season-1]['episodes']):
|
||||||
#the current episode is not the last one of the season
|
#the current episode is not the last one of the season
|
||||||
episode += 1
|
episode += 1
|
||||||
|
|
||||||
#check if the season is the last one
|
#check if the season is the last one
|
||||||
elif((season+1) < maximum_number_seasons):
|
elif((season) < maximum_number_seasons):
|
||||||
season += 1
|
season += 1
|
||||||
episode = 1
|
episode = 1
|
||||||
else:
|
else:
|
||||||
print("You watched the last episode of the serie")
|
print("You watched the last episode of the serie")
|
||||||
lastEpisode = True
|
lastEpisode = True
|
||||||
return season,episode,lastEpisode
|
return season,episode,lastEpisode
|
||||||
Reference in New Issue
Block a user