39 Commits
Author SHA1 Message Date
pierre geeraert 3315fbdb4f change the DB settings and change the policy to restart after build
Gitea Actions Demo / Explore-Gitea-Actions (push) Successful in 5m27s
2025-06-22 19:24:22 +01:00
pierre geeraert 5bbe4c5c61 work on the simpsons generator using the DB
Gitea Actions Demo / Explore-Gitea-Actions (push) Successful in 6m57s
2025-06-22 19:14:36 +01:00
Pierre Geeraert 2366d0c2a8 Revert "try without the cache git actions"
Gitea Actions Demo / Explore-Gitea-Actions (push) Successful in 3m41s
This reverts commit a4d9f63568.
2025-06-03 11:48:12 +01:00
Pierre Geeraert a4d9f63568 try without the cache git actions
Gitea Actions Demo / Explore-Gitea-Actions (push) Has been cancelled
2025-06-03 11:46:04 +01:00
Pierre Geeraert 496f2b3bfb modify cache directory
Gitea Actions Demo / Explore-Gitea-Actions (push) Successful in 3m56s
2025-06-03 11:39:40 +01:00
Pierre Geeraert cb7a010fb6 modify cache directory
Gitea Actions Demo / Explore-Gitea-Actions (push) Has been cancelled
2025-06-03 11:20:14 +01:00
Pierre Geeraert 5b5093708d modify cache directory
Gitea Actions Demo / Explore-Gitea-Actions (push) Has been cancelled
2025-06-03 11:12:46 +01:00
Pierre Geeraert 975252656f modify cache directory
Gitea Actions Demo / Explore-Gitea-Actions (push) Successful in 3m23s
2025-06-03 11:07:43 +01:00
Pierre Geeraert 0b7da7a5c9 cache works but I want local
Gitea Actions Demo / Explore-Gitea-Actions (push) Successful in 4m30s
2025-06-03 10:57:01 +01:00
Pierre Geeraert 4e70e2d28d change key for git action cache
Gitea Actions Demo / Explore-Gitea-Actions (push) Successful in 5m19s
2025-06-03 10:48:40 +01:00
Pierre Geeraert 705db14521 commenting ,from=pip_cache 2025-06-03 10:47:34 +01:00
Pierre Geeraert 5b5d62e4fa commenting build-contexts
Gitea Actions Demo / Explore-Gitea-Actions (push) Failing after 57s
2025-06-03 10:45:53 +01:00
Pierre Geeraert 9afe770202 try to use cache
Gitea Actions Demo / Explore-Gitea-Actions (push) Failing after 1m40s
2025-06-03 10:43:15 +01:00
Pierre Geeraert 6a52ed2f66 try to use cache
Gitea Actions Demo / Explore-Gitea-Actions (push) Successful in 3m20s
2025-06-03 10:28:43 +01:00
pierre geeraert 279d59e376 change the action
Gitea Actions Demo / Explore-Gitea-Actions (push) Successful in 3m14s
2025-06-02 23:54:34 +01:00
pierre geeraert a6d9f29f1a change the action 2025-06-02 23:52:20 +01:00
pierre geeraert bb36edfca5 change the action 2025-06-02 23:51:27 +01:00
pierre geeraert f451b8ff3b change the action 2025-06-02 23:50:30 +01:00
pierre geeraert b837e1a952 change the action
Gitea Actions Demo / Explore-Gitea-Actions (push) Successful in 3m3s
2025-06-02 23:41:01 +01:00
pierre geeraert aa1501214d update the number of replicas 2025-06-02 23:37:56 +01:00
pierre geeraert 246eff86a6 test the action
Gitea Actions Demo / Explore-Gitea-Actions (push) Successful in 44s
2025-06-02 23:13:12 +01:00
pierre geeraert e2ea76c6c9 change the action 2025-06-02 23:12:21 +01:00
pierre geeraert ad4fe6df26 change the action 2025-06-02 23:10:30 +01:00
pierre geeraert 43a000a9c1 fixing the wrong redirect
Gitea Actions Demo / Explore-Gitea-Actions (push) Successful in 32s
2025-06-02 23:04:03 +01:00
pierre geeraert 32a0e65a68 forgot to remove the baseurl var
Gitea Actions Demo / Explore-Gitea-Actions (push) Successful in 26s
2025-06-02 22:54:14 +01:00
pierre geeraert b80be01a52 change the config file
Gitea Actions Demo / Explore-Gitea-Actions (push) Successful in 24s
2025-06-02 22:47:01 +01:00
pi-ux-ce daa935bbef update the secret for kubeconfig
Gitea Actions Demo / Explore-Gitea-Actions (push) Successful in 26s
2025-06-02 22:39:49 +01:00
pierre geeraert cb49bfba58 change the config file
Gitea Actions Demo / Explore-Gitea-Actions (push) Successful in 27s
2025-06-02 22:38:26 +01:00
pierre geeraert 60af5e87ce adding views for kubernetes connection
Gitea Actions Demo / Explore-Gitea-Actions (push) Successful in 26s
2025-06-02 22:19:02 +01:00
Pierre Geeraert aad687f630 enable more view effects
Gitea Actions Demo / Explore-Gitea-Actions (push) Successful in 26s
2025-06-02 17:38:48 +01:00
pi-ux-ce 6b30f381df Merge branch 'main' of https://gitea.tryton.geeraert.eu/pi-ux-ce/Django_kube
Gitea Actions Demo / Explore-Gitea-Actions (push) Successful in 35s
2025-06-02 14:40:48 +01:00
Pierre Geeraert 5b03dc35b4 add urls for view
Gitea Actions Demo / Explore-Gitea-Actions (push) Successful in 25s
2025-06-02 14:01:34 +01:00
pi-ux-ce f9732160f0 try to use only the code from the docker image
Gitea Actions Demo / Explore-Gitea-Actions (push) Successful in 24s
2025-06-02 13:59:10 +01:00
Pierre Geeraert 8a84a8d42f works on the view
Gitea Actions Demo / Explore-Gitea-Actions (push) Successful in 27s
2025-06-02 13:52:01 +01:00
Pierre Geeraert 39e6a69a08 fix the syntax error
Gitea Actions Demo / Explore-Gitea-Actions (push) Successful in 27s
2025-06-02 10:58:21 +01:00
pi-ux-ce c9d6d77931 dependencies for bootstrap
Gitea Actions Demo / Explore-Gitea-Actions (push) Successful in 26s
2025-06-02 09:39:05 +00:00
pi-ux-ce 2f30234edd Update requirements.txt
Gitea Actions Demo / Explore-Gitea-Actions (push) Successful in 34s
2025-06-02 09:01:05 +00:00
pi-ux-ce cdd1dd0245 Update .gitea/workflows/dockerfile_runner.yaml
Gitea Actions Demo / Explore-Gitea-Actions (push) Successful in 28s
2025-06-02 08:40:36 +00:00
pi-ux-ce df9d6c93cc Merge pull request 'working on views' (#1) from view into main
Gitea Actions Demo / Explore-Gitea-Actions (push) Successful in 30s
Reviewed-on: #1
2025-06-02 08:36:25 +00:00
11 changed files with 412 additions and 47 deletions
+25 -7
View File
@@ -2,12 +2,8 @@ name: Gitea Actions Demo
run-name: ${{ gitea.actor }} is testing out Gitea Actions 🚀 run-name: ${{ gitea.actor }} is testing out Gitea Actions 🚀
on: on:
push: push:
branches: issue_comment:
- "*" types: [created]
paths:
- 'dockerfile'
tags-ignore:
- '*'
jobs: jobs:
Explore-Gitea-Actions: Explore-Gitea-Actions:
@@ -20,6 +16,20 @@ jobs:
- name: List files in the repository - name: List files in the repository
run: | run: |
ls ${{ gitea.workspace }} ls ${{ gitea.workspace }}
- name: Cache pip
uses: actions/cache@v3
with:
path: /root/.cache/pip
key: pip
restore-keys: pip
- name: inject cache into docker
uses: reproducible-containers/buildkit-cache-dance@v3.1.0
with:
cache-source: /root/.cache/pip
- name: Set up Docker Buildx - name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3 uses: docker/setup-buildx-action@v3
@@ -34,7 +44,15 @@ jobs:
uses: docker/build-push-action@v6 uses: docker/build-push-action@v6
with: with:
push: true push: true
#build-contexts: pip_cache=${{steps.vars.outputs.pip-dir}}
tags: gitea.tryton.geeraert.eu/pi-ux-ce/django-python:latest tags: gitea.tryton.geeraert.eu/pi-ux-ce/django-python:latest
cache-from: type=registry,ref=gitea.tryton.geeraert.eu/pi-ux-ce/django-python:buildcache
cache-to: type=registry,ref=gitea.tryton.geeraert.eu/pi-ux-ce/django-python:buildcache,mode=max
- name: drop the pod to force pulling the new image
uses: actions-hub/kubectl@master
env:
KUBE_CONFIG: ${{ secrets.KUBE_CONFIG }}
with:
args: rollout restart deployment django -n django
- run: echo "🍏 This job's status is ${{ job.status }}." - run: echo "🍏 This job's status is ${{ job.status }}."
+8 -1
View File
@@ -1,6 +1,13 @@
name: Gitea Actions Demo name: Gitea Actions Demo
run-name: ${{ gitea.actor }} is testing out Gitea Actions 🚀 run-name: ${{ gitea.actor }} is testing out Gitea Actions 🚀
on: [push] on:
push:
branches:
- "*"
paths:
- '*.yaml'
tags-ignore:
- '*'
jobs: jobs:
Explore-Gitea-Actions: Explore-Gitea-Actions:
+9 -2
View File
@@ -26,11 +26,14 @@ spec:
- containerPort: 8000 - containerPort: 8000
name: webserver-port name: webserver-port
volumeMounts: volumeMounts:
- name: django-python-code ## - name: django-python-code
mountPath: /code # mountPath: /code
- name: servarr-data - name: servarr-data
mountPath: /data mountPath: /data
readOnly: true readOnly: true
- name: secret-kubeconfig
mountPath: /kubeconfig
resources: resources:
limits: limits:
@@ -43,6 +46,10 @@ spec:
- name: servarr-data - name: servarr-data
hostPath: hostPath:
path: /data path: /data
- name: secret-kubeconfig
secret:
defaultMode: 420
secretName: kubeconfig
--- ---
@@ -0,0 +1,134 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<title>Scaled down</title>
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto|Varela+Round">
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/css/bootstrap.min.css">
<link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css">
<script src="https://code.jquery.com/jquery-3.5.1.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/popper.js@1.16.0/dist/umd/popper.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/js/bootstrap.min.js"></script>
<style>
body {
font-family: 'Varela Round', sans-serif;
}
.modal-confirm {
color: #636363;
width: 325px;
font-size: 14px;
}
.modal-confirm .modal-content {
padding: 20px;
border-radius: 5px;
border: none;
}
.modal-confirm .modal-header {
border-bottom: none;
position: relative;
}
.modal-confirm h4 {
text-align: center;
font-size: 26px;
margin: 30px 0 -15px;
}
.modal-confirm .form-control, .modal-confirm .btn {
min-height: 40px;
border-radius: 3px;
}
.modal-confirm .close {
position: absolute;
top: -5px;
right: -5px;
}
.modal-confirm .modal-footer {
border: none;
text-align: center;
border-radius: 5px;
font-size: 13px;
}
.modal-confirm .icon-box {
color: #fff;
position: absolute;
margin: 0 auto;
left: 0;
right: 0;
top: -70px;
width: 105px;
height: 105px;
border-radius: 50%;
z-index: 9;
/*background: #82ce34;*/
background: #a80505;
padding: 15px;
text-align: center;
box-shadow: 0px 2px 2px rgba(0, 0, 0, 0.1);
}
.modal-confirm .icon-box i {
font-size: 58px;
position: relative;
top: 0px;
}
.modal-confirm .icon-box:hover,.modal-confirm .icon-box:focus {
background: #6fb32b;
/*background: #a80505;*/
outline: none;
}
.modal-confirm.modal-dialog {
margin-top: 80px;
}
.modal-confirm .btn {
color: #fff;
border-radius: 4px;
/*background: #82ce34;*/
background: #a80505;
text-decoration: none;
transition: all 0.4s;
line-height: normal;
border: none;
}
.modal-confirm .btn:hover, .modal-confirm .btn:focus {
background: #800404;
/*background: #a80505;*/
outline: none;
}
.trigger-btn {
display: inline-block;
margin: 100px auto;
}
</style>
</head>
<body>
<div class="text-center">
<!-- Button HTML (to Trigger Modal) -->
<!--<a href="#myModal" class="trigger-btn" data-toggle="modal">Click to Open Confirm Modal</a> -->
<!-- Modal HTML -->
<!--<div id="myModal" class="modal fade">-->
<div class="modal-dialog modal-confirm">
<div class="modal-content">
<div class="modal-header">
<div class="icon-box" onclick="window.location='/kubernetes_connection/scale_up/{{namespace}}/{{deployment}}';">
<!--<i class="material-icons">&#xE876;</i>-->
<i class="material-icons">&#xd7;</i>
</div>
<h4 class="modal-title w-100">Too bad!</h4>
</div>
<div class="modal-body">
<p class="text-center">{{ deployment }} deployment from namespace {{ namespace }} is now scaled down.</p>
<p class="text-center">Current URL {{ url }}.</p>
<p class="text-center">base URL {{ baseurl }}.</p>
</div>
<div href={{ url }} class="modal-footer">
<!--<button href={{ url }} class="btn btn-success btn-block" data-dismiss="modal">Redirect</button>-->
<a href="https://google.fr" class="btn btn-success btn-block" data-dismiss="modal">Redirect</a>
</div>
</div>
</div>
</div>
</div>
</body>
</html>
+133
View File
@@ -0,0 +1,133 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<title>Scaled up</title>
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto|Varela+Round">
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/css/bootstrap.min.css">
<link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css">
<script src="https://code.jquery.com/jquery-3.5.1.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/popper.js@1.16.0/dist/umd/popper.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/js/bootstrap.min.js"></script>
<style>
body {
font-family: 'Varela Round', sans-serif;
}
.modal-confirm {
color: #636363;
width: 325px;
font-size: 14px;
}
.modal-confirm .modal-content {
padding: 20px;
border-radius: 5px;
border: none;
}
.modal-confirm .modal-header {
border-bottom: none;
position: relative;
}
.modal-confirm h4 {
text-align: center;
font-size: 26px;
margin: 30px 0 -15px;
}
.modal-confirm .form-control, .modal-confirm .btn {
min-height: 40px;
border-radius: 3px;
}
.modal-confirm .close {
position: absolute;
top: -5px;
right: -5px;
}
.modal-confirm .modal-footer {
border: none;
text-align: center;
border-radius: 5px;
font-size: 13px;
}
.modal-confirm .icon-box {
color: #fff;
position: absolute;
margin: 0 auto;
left: 0;
right: 0;
top: -70px;
width: 95px;
height: 95px;
border-radius: 50%;
z-index: 9;
background: #82ce34;
padding: 15px;
text-align: center;
box-shadow: 0px 2px 2px rgba(0, 0, 0, 0.1);
}
.modal-confirm .icon-box i {
font-size: 58px;
position: relative;
top: 3px;
}
.modal-confirm .icon-box:hover,.modal-confirm .icon-box:focus {
/*background: #6fb32b;*/
background: #a80505;
outline: none;
}
.modal-confirm.modal-dialog {
margin-top: 80px;
}
.modal-confirm .btn {
color: #fff;
border-radius: 4px;
background: #82ce34;
text-decoration: none;
transition: all 0.4s;
line-height: normal;
border: none;
}
.modal-confirm .btn:hover, .modal-confirm .btn:focus {
background: #6fb32b;
/*background: #a80505;*/
outline: none;
}
.trigger-btn {
display: inline-block;
margin: 100px auto;
}
</style>
</head>
<body>
<div class="text-center">
<!-- Button HTML (to Trigger Modal) -->
<!--<a href="#myModal" class="trigger-btn" data-toggle="modal">Click to Open Confirm Modal</a> -->
<!-- Modal HTML -->
<!--<div id="myModal" class="modal fade">-->
<div class="modal-dialog modal-confirm">
<div class="modal-content">
<div class="modal-header">
<div class="icon-box" onclick="window.location='/kubernetes_connection/scale_down/{{namespace}}/{{deployment}}';">
<!--<i class="material-icons">&#xE876;</i>-->
<i class="material-icons">&#xE876;</i>
</div>
<h4 class="modal-title w-100">Awesome!</h4>
</div>
<div class="modal-body">
<p class="text-center">{{ deployment }} deployment from namespace {{ namespace }} is now scaled up.</p>
<p class="text-center">Current URL {{ url }}.</p>
<p class="text-center">base URL {{ baseurl }}.</p>
</div>
<div href={{ url }} class="modal-footer">
<!--<button href={{ url }} class="btn btn-success btn-block" data-dismiss="modal">Redirect</button>-->
<a href="https://google.fr" class="btn btn-success btn-block" data-dismiss="modal">Redirect</a>
</div>
</div>
</div>
</div>
</div>
</body>
</html>
+12
View File
@@ -1,5 +1,6 @@
from django.shortcuts import render from django.shortcuts import render
def home(request): def home(request):
thislist = ["apple", "banana", "cherry"] thislist = ["apple", "banana", "cherry"]
return render(request, 'home.html',{'thislist': thislist}) return render(request, 'home.html',{'thislist': thislist})
@@ -7,3 +8,14 @@ def home(request):
def about(request): def about(request):
thislist = ["apple", "banana", "cherry"] thislist = ["apple", "banana", "cherry"]
return render(request, 'about.html',{'thislist': thislist}) return render(request, 'about.html',{'thislist': thislist})
def success(request):
return render(request, 'start.html',{'deployment': 'django','url':'https://google.com'})
def scale_up(request,namespace_name,deploy_name):
baseurl = "{0}://{1}{2}".format(request.scheme, request.get_host(), request.path)
return render(request, 'start.html', {'namespace':namespace_name,'deployment': deploy_name, 'url': 'https://namespace.com','baseurl': baseurl})
def scale_down(request,namespace_name,deploy_name):
baseurl = "{0}://{1}{2}".format(request.scheme, request.get_host(), request.path)
return render(request, 'shutdown.html', {'namespace':namespace_name,'deployment': deploy_name, 'url': 'https://namespace.com','baseurl': baseurl})
+4
View File
@@ -43,6 +43,10 @@ urlpatterns = [
path('dashboard/hello/', dashboardapp.hello), path('dashboard/hello/', dashboardapp.hello),
path('dashboard/view/about', dashboardview.about), path('dashboard/view/about', dashboardview.about),
path('dashboard/view/home', dashboardview.home), path('dashboard/view/home', dashboardview.home),
path('dashboard/view/success', dashboardview.success),
path('dashboard/scale_up/<str:namespace_name>/<str:deploy_name>', dashboardview.scale_up),
path('dashboard/scale_down/<str:namespace_name>/<str:deploy_name>', dashboardview.scale_down),
################## kubernetes_connection##### ################## kubernetes_connection#####
+19 -15
View File
@@ -18,23 +18,26 @@ def hello(request):
return HttpResponse('<h1>Hello k8s!</h1>') return HttpResponse('<h1>Hello k8s!</h1>')
def scale_up(request,namespace_name,deploy_name): def scale_up(request,namespace_name,deploy_name):
config.load_kube_config(config_file='/code/kubeconfig') config.load_kube_config(config_file='/kubeconfig/config')
api = client.AppsV1Api() api = client.AppsV1Api()
deployment = api.read_namespaced_deployment(name=deploy_name, namespace=namespace_name) deployment = api.read_namespaced_deployment(name=deploy_name, namespace=namespace_name)
deployment.spec.replicas = 2 deployment.spec.replicas = 1
resp = api.patch_namespaced_deployment( resp = api.patch_namespaced_deployment(
name=deploy_name, namespace=namespace_name, body=deployment); name=deploy_name, namespace=namespace_name, body=deployment);
return HttpResponse('<h1>Scaled up !</h1>') #return HttpResponse('<h1>Scaled up !</h1>')
return render(request, 'start.html', {'namespace':namespace_name,'deployment': deploy_name, 'url': 'https://namespace.com'})
def scale_down(request,namespace_name,deploy_name): def scale_down(request,namespace_name,deploy_name):
config.load_kube_config(config_file='/code/kubeconfig') config.load_kube_config(config_file='/kubeconfig/config')
api = client.AppsV1Api() api = client.AppsV1Api()
deployment = api.read_namespaced_deployment(name=deploy_name, namespace=namespace_name) deployment = api.read_namespaced_deployment(name=deploy_name, namespace=namespace_name)
deployment.spec.replicas = 0 deployment.spec.replicas = 0
resp = api.patch_namespaced_deployment( resp = api.patch_namespaced_deployment(
name=deploy_name, namespace=namespace_name, body=deployment); name=deploy_name, namespace=namespace_name, body=deployment);
return HttpResponse('<h1>Scaled down !</h1>') #return HttpResponse('<h1>Scaled down !</h1>')
return render(request, 'shutdown.html',
{'namespace': namespace_name, 'deployment': deploy_name, 'url': 'https://namespace.com'})
def nodes(request): def nodes(request):
config.load_kube_config(config_file='/code/kubeconfig') config.load_kube_config(config_file='/code/kubeconfig')
@@ -111,15 +114,16 @@ def backup_job(request):
#help with yaml import #help with yaml import
#https://github.com/kubernetes-client/python/issues/589 #https://github.com/kubernetes-client/python/issues/589
def backup_job_yaml(request): def backup_job_yaml(request,sync_target):
config.load_kube_config(config_file='/code/kubeconfig') config.load_kube_config(config_file='/code/kubeconfig')
v1 = client.BatchV1Api() v1 = client.BatchV1Api()
with urllib.request.urlopen(https://gitea.tryton.geeraert.eu/pi-ux-ce/Backup_kube/raw/branch/main/Infrequent_access/pod.yaml") as manifest_url: yaml_location = {
"synology" : "https://gitea.tryton.geeraert.eu/pi-ux-ce/Backup_kube/raw/branch/main/Infrequent_access/synology_pod.yaml",
"openmediavault":"https://gitea.tryton.geeraert.eu/pi-ux-ce/Backup_kube/raw/branch/main/Infrequent_access/openmediavault_pod.yaml"
}
print(yaml_location[sync_target])
url_to_select=yaml_location[sync_target]
api_response = v1.create_namespaced_job(body=pod_manifest_job)
# with open('/code/pod.yaml') as : return HttpResponse(api_response)
job = yaml.safe_load(manifest_url)
v1.create_namespaced_job(
job['metadata']['namespace'], job, pretty=True
)
return HttpResponse(job['metadata']['namespace'])
+61 -17
View File
@@ -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,46 @@ 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-"; #dev settings
simpsons_url = "https://kisscartoon.top/episode/the-simpsons-season-"; #generated_db = DB_generation("192.168.88.50",32345, "django_username", "Suffrage-Moneybags-Illusion7","django")
number_of_seasons = 35 #production settings
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] generated_db = DB_generation("django-db-svc",5432, "django_username", "Suffrage-Moneybags-Illusion7","django")
#print(simpsons_url) cursor = generated_db.cursor()
random_seasons = random.randint(1, number_of_seasons) #get max number of season
print("random seasons: "+ str(random_seasons)) maximum_number_of_seasons = Launch_sql_query("SELECT COUNT(DISTINCT season) as result FROM episodes;",generated_db)
#random_seasons-1 because list start at index 0 boolean_restart = True;
print("maximum of episode for this season: "+str(seasons_maximum_number[random_seasons-1])) while (boolean_restart):
random_episode = random.randint(1, seasons_maximum_number[random_seasons-1]) random_seasons = random.randint(1, maximum_number_of_seasons)
print("random season: " + str(random_seasons))
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))
+2 -2
View File
@@ -5,8 +5,8 @@ WORKDIR /code/
COPY requirements.txt ./ COPY requirements.txt ./
COPY django_code ./ COPY django_code ./
RUN pip install --upgrade pip RUN --mount=type=cache,target=/root/.cache/pip pip install --upgrade pip
RUN pip install --no-cache-dir -r requirements.txt RUN --mount=type=cache,target=/root/.cache/pip pip install --no-cache-dir -r requirements.txt
COPY . . COPY . .
RUN python django_code/manage.py migrate RUN python django_code/manage.py migrate
+2
View File
@@ -1,7 +1,9 @@
django django
psycopg2
requests requests
proxmoxer proxmoxer
docker docker
kubernetes kubernetes
ruamel.yaml ruamel.yaml
pyyaml pyyaml
django-bootstrap-v5