work on the simpsons generator using the DB
Gitea Actions Demo / Explore-Gitea-Actions (push) Successful in 6m57s
Gitea Actions Demo / Explore-Gitea-Actions (push) Successful in 6m57s
This commit is contained in:
@@ -7,9 +7,34 @@ from django.core.files import File
|
|||||||
|
|
||||||
#from django.template.loader import render_to_string
|
#from django.template.loader import render_to_string
|
||||||
import time
|
import time
|
||||||
|
import psycopg2
|
||||||
import random
|
import random
|
||||||
import mimetypes
|
import mimetypes
|
||||||
|
|
||||||
|
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):
|
def hello(request):
|
||||||
return HttpResponse('<h1>Hello Simpsons!</h1>')
|
return HttpResponse('<h1>Hello Simpsons!</h1>')
|
||||||
#<h1>href="{{ STATIC_URL }}/files/somefile</h1>)
|
#<h1>href="{{ STATIC_URL }}/files/somefile</h1>)
|
||||||
@@ -42,27 +67,42 @@ def download_mo(request,file):
|
|||||||
#return HttpResponse('<h1>Hello !</h1>')
|
#return HttpResponse('<h1>Hello !</h1>')
|
||||||
|
|
||||||
def simpsons(request):
|
def simpsons(request):
|
||||||
# simpsons_url = "https://www1.kisscartoon.online/episode/the-simpsons-season-";
|
generated_db = DB_generation("192.168.88.50",32345, "django_username", "Suffrage-Moneybags-Illusion7","django")
|
||||||
simpsons_url = "https://kisscartoon.top/episode/the-simpsons-season-";
|
cursor = generated_db.cursor()
|
||||||
number_of_seasons = 35
|
|
||||||
seasons_maximum_number = [13,22,24,22,22,25,25,25,25,23,22,21,22,22,22,21,22,22,20,21,23,22,22,22,22,22,22,22,21,23,22,22,22,22,18]
|
|
||||||
|
|
||||||
#print(simpsons_url)
|
#get max number of season
|
||||||
|
maximum_number_of_seasons = Launch_sql_query("SELECT COUNT(DISTINCT season) as result FROM episodes;",generated_db)
|
||||||
|
|
||||||
random_seasons = random.randint(1, number_of_seasons)
|
boolean_restart = True;
|
||||||
print("random seasons: "+ str(random_seasons))
|
while (boolean_restart):
|
||||||
|
|
||||||
#random_seasons-1 because list start at index 0
|
random_seasons = random.randint(1, maximum_number_of_seasons)
|
||||||
print("maximum of episode for this season: "+str(seasons_maximum_number[random_seasons-1]))
|
print("random season: " + str(random_seasons))
|
||||||
|
|
||||||
random_episode = random.randint(1, seasons_maximum_number[random_seasons-1])
|
|
||||||
|
|
||||||
print("random episode: "+ str(random_episode))
|
|
||||||
|
|
||||||
|
|
||||||
final_url = simpsons_url+str(random_seasons)+ "-episode-"+str(random_episode)#
|
#get max number of epiosde for this season
|
||||||
print(final_url)
|
maximum_number_of_episodes_query = "SELECT COUNT(url) as result FROM episodes WHERE season = " + str(random_seasons) + ";"
|
||||||
|
|
||||||
return HttpResponse(str(final_url))
|
maximum_number_of_episodes = Launch_sql_query(maximum_number_of_episodes_query,generated_db)
|
||||||
# time.sleep(10)
|
|
||||||
# return redirect(str(final_url))
|
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))
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
django
|
django
|
||||||
|
psycopg2
|
||||||
requests
|
requests
|
||||||
proxmoxer
|
proxmoxer
|
||||||
docker
|
docker
|
||||||
|
|||||||
Reference in New Issue
Block a user