76 lines
2.7 KiB
Python
76 lines
2.7 KiB
Python
from django.http import HttpResponse
|
|
from django.db.models import Count
|
|
from django.shortcuts import redirect
|
|
from .models import SimpsonsData,simpsons_data_object
|
|
from .utils import mark_episode_watched
|
|
import random
|
|
import threading
|
|
|
|
def hello(request):
|
|
return HttpResponse('<h1>Hello Simpsons view!</h1>')
|
|
|
|
def episode_generator(request):
|
|
boolean_restart = True;
|
|
simpsons_object = {}
|
|
while (boolean_restart):
|
|
maximum_number_of_seasons = simpsons_data_object.aggregate(unique_season=Count('season', distinct=True))['unique_season']
|
|
|
|
random_season = random.randint(1, maximum_number_of_seasons)
|
|
print("random season: " + str(random_season))
|
|
|
|
simpsons_object = simpsons_data_object.filter(season=random_season)
|
|
|
|
maximum_number_of_episodes = simpsons_object.count()
|
|
|
|
random_episode = random.randint(1, maximum_number_of_episodes)
|
|
print("random episode: " + str(random_episode))
|
|
|
|
simpsons_object = simpsons_object.filter(episode=random_episode)
|
|
|
|
episode_seen = simpsons_object.values('seen')[0]['seen']
|
|
|
|
if not(episode_seen):
|
|
boolean_restart = False
|
|
else:
|
|
print("episode "+str(random_episode)+" from season "+str(random_season)+" already seen")
|
|
|
|
|
|
#Set episode as seen
|
|
# It will still update an already seem episode but it works and I'm lazy
|
|
|
|
|
|
#Mark episode as seen on betaseries
|
|
thread = threading.Thread(
|
|
target=mark_episode_watched,
|
|
args=(random_season, random_episode, "watched"),
|
|
daemon=True,
|
|
)
|
|
thread.start()
|
|
|
|
random_url = simpsons_object.values('url')[0]['url']
|
|
|
|
return redirect(str(random_url))
|
|
|
|
def download_file(request):
|
|
# fill these variables with real values
|
|
fl_path = '/data/download/sonarr'
|
|
filename = 'The.Boys.2019.S04E05.2160p.HDR10Plus.WEBRip.6CH.x265.HEVC-PSA.mkv'
|
|
|
|
# fl = open(fl_path, 'r')
|
|
# mime_type, _ = mimetypes.guess_type(fl_path)
|
|
|
|
# response = HttpResponse(fl, content_type=mime_type)
|
|
# response['Content-Disposition'] = "attachment; filename=%s" % filename
|
|
some_file = open('/data/kubernetes/Backup/nextcloud/notes/2024-07-28/Course.md', "r")
|
|
django_file = File(some_file)
|
|
return HttpResponse("<h1>Hello download!</h1><h1><a href='{{ MEDIA_URL }}{{ django_file.relative_path }}'>{{ django_file.name }}</a></h1><h1>bye download!</h1>")
|
|
# return response
|
|
|
|
def download_mo(request,file):
|
|
path_to_file = os.path.realpath(file)
|
|
response = FileResponse(open(path_to_file, 'rb'))
|
|
file_name = file[5:]
|
|
response['Content-Disposition'] = 'inline; filename=' + file_name
|
|
return response
|
|
|