🗑️ cleaning
Gitea Actions Demo / Explore-Gitea-Actions (push) Successful in 3s

This commit is contained in:
2026-06-17 18:59:14 +01:00
parent 47bf1d40f9
commit 2da9e9390d
3 changed files with 28 additions and 123 deletions
+1 -112
View File
@@ -1,117 +1,6 @@
from django.apps import AppConfig
from django.http import HttpResponse
from django.shortcuts import render
from django.shortcuts import redirect
from django.core.files import File
#from django.template.loader import render_to_string
import time
import psycopg2
import random
import mimetypes
class RandomSimpsonsConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'apps.random_simpsons'
label = 'simpsons'
def DB_generation(host_in,port_in,user_in,password_in,db_in):
#db = pymysql.connect(host=host_in, port=port_in, user=user_in, passwd=password_in,db=db_in)
db = psycopg2.connect(host=host_in, port=port_in, user=user_in, password=password_in,database=db_in)
return db
def Launch_sql_query(sql,db):
#sql query with 1 object returned
cursor = db.cursor()
try:
# Execute the SQL command
cursor.execute(sql)
# Fetch all the rows in a list of lists.
results = cursor.fetchall()
for row in results:
return row[0]
except:
print ("Error: unable to fetch data from the query:")
print (sql)
print("---")
cursor.close()
def hello(request):
return HttpResponse('<h1>Hello Simpsons!</h1>')
#<h1>href="{{ STATIC_URL }}/files/somefile</h1>)
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
#def template(request):
# rendered = render_to_string("random_simpsons/my_template.html", {"foo": "bar"})
#return HttpResponse('<h1>Hello !</h1>')
def simpsons(request):
#dev settings
#generated_db = DB_generation("192.168.88.50",32345, "django_username", "Suffrage-Moneybags-Illusion7","django")
#production settings
generated_db = DB_generation("django-db-svc",5432, "django_username", "Suffrage-Moneybags-Illusion7","django")
cursor = generated_db.cursor()
#get max number of season
maximum_number_of_seasons = Launch_sql_query("SELECT COUNT(DISTINCT season) as result FROM episodes;",generated_db)
boolean_restart = True;
while (boolean_restart):
random_seasons = random.randint(1, maximum_number_of_seasons)
print("random season: " + str(random_seasons))
#get max number of epiosde for this season
maximum_number_of_episodes_query = "SELECT COUNT(url) as result FROM episodes WHERE season = " + str(random_seasons) + ";"
maximum_number_of_episodes = Launch_sql_query(maximum_number_of_episodes_query,generated_db)
random_episode = random.randint(1, maximum_number_of_episodes)
print("random episode: " + str(random_episode))
#check if the episode was already seen
check_if_already_seen_query = "select seen from episodes where season="+ str(random_seasons) +" and episode = "+ str(random_episode) +";"
if not Launch_sql_query(check_if_already_seen_query, generated_db):
boolean_restart = False
else:
print("episode "+str(random_episode)+" from season "+str(random_seasons)+" already seen")
url_from_episode_season_query = "select url from episodes where season="+ str(random_seasons) +" and episode = "+ str(random_episode) +";"
generated_url = Launch_sql_query(url_from_episode_season_query,generated_db)
#mark as seen
url_from_episode_season_query = "update episodes set seen = True where season=" + str(random_seasons) + " and episode = " + str(random_episode) + ";"
Launch_sql_query(url_from_episode_season_query, generated_db)
generated_db.commit()
generated_db.close()
#return HttpResponse(str(generated_url))
return redirect(str(generated_url))
label = 'simpsons'
+25 -7
View File
@@ -1,16 +1,12 @@
from django.shortcuts import render
import random
# Create your views here.
from django.http import HttpResponse
from django.db.models import Count
from django.shortcuts import redirect
from apps.random_simpsons.models import SimpsonsData
import random
def hello(request):
return HttpResponse('<h1>Hello Django!</h1>')
return HttpResponse('<h1>Hello Simpsons view!</h1>')
def episode_generator(request):
simpsons_data_object = SimpsonsData.objects.using('simpsons_db')
@@ -41,4 +37,26 @@ def episode_generator(request):
simpsons_data_object.filter(season=random_seasons, episode=random_episode).values('seen').update(seen=True)
return redirect(str(random_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