Compare commits
265
Commits
78cc6cbad3
...
testing
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3ff4f98841 | ||
|
|
0a8c337b1e | ||
|
|
2dac0d1f53 | ||
|
|
73b627214d | ||
|
|
c79168453b | ||
|
|
299f72abca | ||
|
|
058125f0b1 | ||
|
|
130b0af8d8 | ||
|
|
6f7542ef27 | ||
|
|
919d1a3a28 | ||
|
|
3c4c32e72d | ||
|
|
3294e70b3f | ||
|
|
5908d8d282 | ||
|
|
32f8251a90 | ||
|
|
a3fec86eae | ||
|
|
672edccd70 | ||
|
|
f188e25453 | ||
|
|
d4a72ebf5d | ||
|
|
4492db4185 | ||
|
|
015edcd63d | ||
|
|
aaad6b2b7e | ||
|
|
3b6eccba80 | ||
|
|
44b730dbfc | ||
|
|
ea4ebb0de0 | ||
|
|
3b3e82f16a | ||
|
|
1430afe600 | ||
|
|
e3f01da175 | ||
|
|
7a5c7b6de9 | ||
|
|
c880172aa5 | ||
|
|
6b631fb3e3 | ||
|
|
712f3d50b5 | ||
|
|
f6875b498b | ||
|
|
2e728d4698 | ||
|
|
98a969fa04 | ||
|
|
154717aca7 | ||
|
|
cc0eb74090 | ||
|
|
e2f49a5b1f | ||
|
|
c8ceaab950 | ||
|
|
3fbf333d3d | ||
|
|
3cb09b34da | ||
|
|
1d9d723ce9 | ||
|
|
cf06bfd1bd | ||
|
|
df7340e578 | ||
|
|
7a02fb89f4 | ||
|
|
bfdf8b3b2a | ||
|
|
1ae2917263 | ||
|
|
1fea1c9e23 | ||
|
|
fa804dbed1 | ||
|
|
3b28145d0a | ||
|
|
e9bf6ba7b5 | ||
|
|
cc3394d5eb | ||
|
|
90156a4733 | ||
|
|
314a6f1bed | ||
|
|
eab0ddd697 | ||
|
|
3c1960f015 | ||
|
|
3ff4dd1fae | ||
|
|
dbeaf4c58c | ||
|
|
0f49484a43 | ||
|
|
b540c7b7e8 | ||
|
|
1012ea31ad | ||
|
|
a00baa490f | ||
|
|
bc9e331c68 | ||
|
|
57f58b0c9a | ||
|
|
496a6bd940 | ||
|
|
2bbdad3e47 | ||
|
|
91e0c992ec | ||
|
|
860de928ba | ||
|
|
9d82d61993 | ||
|
|
294af1945d | ||
|
|
430172911e | ||
|
|
38e00d6ac6 | ||
|
|
75004d16f9 | ||
|
|
47e6d6630d | ||
|
|
d9366b665b | ||
|
|
951bf0a807 | ||
|
|
4145db089f | ||
|
|
a2f6d43398 | ||
|
|
5e41927b8d | ||
|
|
ea9459f013 | ||
|
|
c2e34305eb | ||
|
|
a79a9623b6 | ||
|
|
cac74471aa | ||
|
|
afe668cca6 | ||
|
|
2785eecbf3 | ||
|
|
0833a20347 | ||
|
|
95945cd4cf | ||
|
|
fdb32538bf | ||
|
|
d2740d4b62 | ||
|
|
e26ba6d99d | ||
|
|
f419751206 | ||
|
|
70660fbd5a | ||
|
|
a94390916a | ||
|
|
5d6e5339ad | ||
|
|
b9cd8e3226 | ||
|
|
ce42b3dc33 | ||
|
|
3f25d83f64 | ||
|
|
45a67a11cf | ||
|
|
f0b700a688 | ||
|
|
8d6234927c | ||
|
|
189f81d95b | ||
|
|
c5d0fd8589 | ||
|
|
1a9ea98202 | ||
|
|
4938370eea | ||
|
|
b834ff10bf | ||
|
|
13c360b1b0 | ||
|
|
7804dd5993 | ||
|
|
87257fb0b5 | ||
|
|
56ccc83903 | ||
|
|
f658a018ac | ||
|
|
2608756622 | ||
|
|
6350dacd4e | ||
|
|
1629715732 | ||
|
|
01c1ce7534 | ||
|
|
ad0b611cb5 | ||
|
|
401ca9f935 | ||
|
|
d3a835e3fb | ||
|
|
e98c05ce08 | ||
|
|
9759416787 | ||
|
|
03b007a5a0 | ||
|
|
93f3646abc | ||
|
|
145e55df92 | ||
|
|
08796241a6 | ||
|
|
8e43ea9dbd | ||
|
|
a42eee7797 | ||
|
|
25caebeb0a | ||
|
|
e157a8c077 | ||
|
|
1d86eb582e | ||
|
|
04a216f643 | ||
|
|
533567b31d | ||
|
|
e568afc5e0 | ||
|
|
8865052752 | ||
|
|
f5f73fcacc | ||
|
|
b438956e96 | ||
|
|
e85c372ad8 | ||
|
|
e66c7034f0 | ||
|
|
8af967b4d3 | ||
|
|
b6e60764bd | ||
|
|
de1977fd2a | ||
|
|
60aafb55b8 | ||
|
|
2b410b5ff8 | ||
|
|
7a1021edfa | ||
|
|
a991b69547 | ||
|
|
9595ea326f | ||
|
|
78a95435ae | ||
|
|
a2973bcd82 | ||
|
|
90cb797d2e | ||
|
|
b496c8ee02 | ||
|
|
cbaf675f09 | ||
|
|
3b2f77df35 | ||
|
|
b4ab48be08 | ||
|
|
943781d54d | ||
|
|
54fd66196e | ||
|
|
12078b1439 | ||
|
|
1a8b54b718 | ||
|
|
749c971e1f | ||
|
|
822c42bd62 | ||
|
|
21e77ab0b3 | ||
|
|
d38cea53f8 | ||
|
|
2e5e3b0a26 | ||
|
|
4dbfeff967 | ||
|
|
441716bbbc | ||
|
|
09b52bc16c | ||
|
|
4f4de780ca | ||
|
|
7681aef96e | ||
|
|
a1d7d8005d | ||
|
|
31179d99de | ||
|
|
d8866b038a | ||
|
|
016ffbb1a9 | ||
|
|
8d90b3ef9d | ||
|
|
7e9b474f10 | ||
|
|
e06a02db13 | ||
|
|
540b5fea80 | ||
|
|
ee91dea395 | ||
|
|
1adc0ffc4a | ||
|
|
b123e260b0 | ||
|
|
aa6ce119b8 | ||
|
|
94e47be079 | ||
|
|
8abcd775ce | ||
|
|
a9a3cf69c6 | ||
|
|
87d8c52c48 | ||
|
|
f3672fed63 | ||
|
|
9f7fdbc198 | ||
|
|
2661593e69 | ||
|
|
6f1c8cd8ff | ||
|
|
a3fb4d843a | ||
|
|
e7b72b1754 | ||
|
|
7cb3d1917e | ||
|
|
0aebb19650 | ||
|
|
3c2e6fe2f1 | ||
|
|
78e9da8bd3 | ||
|
|
b31480b68c | ||
|
|
d556284977 | ||
|
|
d90696a1a5 | ||
|
|
b4eaf9eb5d | ||
|
|
333d065043 | ||
|
|
8aed35a67a | ||
|
|
4fd57edecd | ||
|
|
15e28502c1 | ||
|
|
035b878b3c | ||
|
|
0cbc34293e | ||
|
|
95c11fe68d | ||
|
|
cece5eae71 | ||
|
|
f659209cd6 | ||
|
|
decbfc1bb5 | ||
|
|
e9c7068b52 | ||
|
|
8be9e7dd13 | ||
|
|
f0e6339b3d | ||
|
|
e320f881d1 | ||
|
|
22557fb166 | ||
|
|
919065093d | ||
|
|
c9e66762df | ||
|
|
f1ffa5c949 | ||
|
|
4d5f3809d9 | ||
|
|
b2ef330fc9 | ||
|
|
2ba56cb00f | ||
|
|
d7ef0fcd3e | ||
|
|
c7eb2c5aba | ||
|
|
19e997f7ae | ||
|
|
5433b97b00 | ||
|
|
2a609b2143 | ||
|
|
dfd77e458a | ||
|
|
11d8176622 | ||
|
|
f9f831738d | ||
|
|
a435eac3e8 | ||
|
|
97a74fb2cf | ||
|
|
444039b64a | ||
|
|
7492061f58 | ||
|
|
a44ca7e825 | ||
|
|
f68b0ad00f | ||
|
|
9863662e34 | ||
|
|
7edecd7d1c | ||
|
|
5e9e5a1e7b | ||
|
|
6af4c36fae | ||
|
|
fa61ab2733 | ||
|
|
8764522525 | ||
|
|
b4545d6c99 | ||
|
|
ec2696ee43 | ||
|
|
52ba892d6f | ||
|
|
5478a1032c | ||
|
|
b11c840688 | ||
|
|
15994f11b1 | ||
|
|
b5c3aa1bdb | ||
|
|
623bc9b74e | ||
|
|
6a6b0a0167 | ||
|
|
ad9c6c7a2a | ||
|
|
25b602a3b8 | ||
|
|
ed70f03a83 | ||
|
|
e76fb6684c | ||
|
|
2454d77ce8 | ||
|
|
5432647293 | ||
|
|
14d2e869bb | ||
|
|
ce9072124d | ||
|
|
f78ffcc595 | ||
|
|
57d2559ad3 | ||
|
|
024736c887 | ||
|
|
73f57871b4 | ||
|
|
cf0c355416 | ||
|
|
54c53d4510 | ||
|
|
5e247e831c | ||
|
|
ecaa988b5f | ||
|
|
73c89d8d93 | ||
|
|
1a41a01dfa | ||
|
|
5d26a4dd05 | ||
|
|
956e7fc1d0 | ||
|
|
73101d8cb9 |
@@ -0,0 +1,10 @@
|
|||||||
|
.git
|
||||||
|
.github
|
||||||
|
**/__pycache__
|
||||||
|
*.pyc
|
||||||
|
.pytest_cache
|
||||||
|
media
|
||||||
|
staticfiles
|
||||||
|
*.sqlite3
|
||||||
|
node_modules
|
||||||
|
.env
|
||||||
@@ -1,22 +1,23 @@
|
|||||||
name: Gitea Actions Demo
|
name: Dockerfile runner
|
||||||
run-name: ${{ gitea.actor }} is testing out Gitea Actions 🚀
|
run-name: Building and deploying to Prod 🚀
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
branches:
|
branches:
|
||||||
- main
|
- main
|
||||||
paths-ignore:
|
paths-ignore:
|
||||||
- 'django_testing/dockerfile'
|
- 'infra/production/dockerfile'
|
||||||
issue_comment:
|
issue_comment:
|
||||||
types: [created]
|
types: [created]
|
||||||
|
workflow_dispatch: # Enables the manual run UI button
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
Explore-Gitea-Actions:
|
Explore-Gitea-Actions:
|
||||||
env:
|
env:
|
||||||
RUNNER_TOOL_CACHE: /toolcache
|
RUNNER_TOOL_CACHE: /toolcache
|
||||||
DEBUG: True
|
DEBUG: True
|
||||||
ALLOWED_HOSTS: "django.tryton.geeraert.eu"
|
ALLOWED_HOSTS: "django.geeraert.eu"
|
||||||
container:
|
container:
|
||||||
image: gitea.tryton.geeraert.eu/pi-ux-ce/custom-runner-debian-slim:1.0.6
|
image: gitea.geeraert.eu/pi-ux-ce/custom-runner-debian-slim:1.0.6
|
||||||
volumes:
|
volumes:
|
||||||
- act-toolcache:/opt/hostedtoolcache # this is where Runner store their cache default
|
- act-toolcache:/opt/hostedtoolcache # this is where Runner store their cache default
|
||||||
runs-on: host-runner
|
runs-on: host-runner
|
||||||
@@ -55,47 +56,27 @@ jobs:
|
|||||||
echo "------------------------------------------------"
|
echo "------------------------------------------------"
|
||||||
echo "Next version: $next_version"
|
echo "Next version: $next_version"
|
||||||
|
|
||||||
- name: Cache Docker layers
|
|
||||||
uses: actions/cache@v4
|
|
||||||
with:
|
|
||||||
path: /opt/hostedtoolcache/.buildx-cache
|
|
||||||
key: ${{ runner.os }}-buildx-${{ github.sha }}
|
|
||||||
restore-keys: |
|
|
||||||
${{ runner.os }}-buildx-
|
|
||||||
|
|
||||||
|
|
||||||
- name: inject cache into docker
|
|
||||||
uses: reproducible-containers/buildkit-cache-dance@v3.1.0
|
|
||||||
with:
|
|
||||||
cache-source: /opt/hostedtoolcache/pip
|
|
||||||
|
|
||||||
- name: Set up Docker Buildx
|
|
||||||
uses: docker/setup-buildx-action@v3
|
|
||||||
|
|
||||||
- name: Login to gitea
|
- name: Login to gitea
|
||||||
uses: docker/login-action@v3
|
uses: docker/login-action@v3
|
||||||
with:
|
with:
|
||||||
registry: gitea.tryton.geeraert.eu
|
registry: gitea.geeraert.eu
|
||||||
username: ${{ secrets.USERNAME_GITEA }}
|
username: ${{ secrets.USERNAME_GITEA }}
|
||||||
password: ${{ secrets.PASSWORD_GITEA }}
|
password: ${{ secrets.PASSWORD_GITEA }}
|
||||||
|
|
||||||
- name: Build and push
|
- name: Build image
|
||||||
uses: docker/build-push-action@v6
|
|
||||||
with:
|
|
||||||
push: true
|
|
||||||
build-args: |
|
|
||||||
ALLOWED_HOSTS='django.tryton.geeraert.eu'
|
|
||||||
DEBUG='True'
|
|
||||||
tags: |
|
|
||||||
gitea.tryton.geeraert.eu/pi-ux-ce/django-python:latest
|
|
||||||
gitea.tryton.geeraert.eu/pi-ux-ce/django-python:${{ env.next_version }}
|
|
||||||
cache-from: type=local,src=/opt/hostedtoolcache/.buildx-cache
|
|
||||||
cache-to: type=local,dest=/opt/hostedtoolcache/.buildx-cache-new,mode=max
|
|
||||||
|
|
||||||
- name: Move cache
|
|
||||||
run: |
|
run: |
|
||||||
rm -rf /opt/hostedtoolcache/.buildx-cache
|
docker build \
|
||||||
mv /opt/hostedtoolcache/.buildx-cache-new /opt/hostedtoolcache/.buildx-cache
|
-f infra/production/dockerfile \
|
||||||
|
--build-arg ALLOWED_HOSTS='django.geeraert.eu' \
|
||||||
|
--build-arg DEBUG='True' \
|
||||||
|
-t gitea.geeraert.eu/pi-ux-ce/django-python:latest \
|
||||||
|
-t gitea.geeraert.eu/pi-ux-ce/django-python:${{ env.next_version }} \
|
||||||
|
.
|
||||||
|
|
||||||
|
- name: Push image
|
||||||
|
run: |
|
||||||
|
docker push gitea.geeraert.eu/pi-ux-ce/django-python:latest
|
||||||
|
docker push gitea.geeraert.eu/pi-ux-ce/django-python:${{ env.next_version }}
|
||||||
|
|
||||||
- name: Rollout Django to force pulling the new image
|
- name: Rollout Django to force pulling the new image
|
||||||
uses: actions-hub/kubectl@master
|
uses: actions-hub/kubectl@master
|
||||||
@@ -104,19 +85,13 @@ jobs:
|
|||||||
with:
|
with:
|
||||||
args: rollout restart deployment django -n django
|
args: rollout restart deployment django -n django
|
||||||
|
|
||||||
- name: Rollout Celery worker to force pulling the new image
|
|
||||||
uses: actions-hub/kubectl@master
|
|
||||||
env:
|
|
||||||
KUBE_CONFIG: ${{ secrets.KUBE_CONFIG }}
|
|
||||||
with:
|
|
||||||
args: rollout restart deployment celery-worker -n django
|
|
||||||
- run: echo "🍏 This job's status is ${{ job.status }}."
|
- run: echo "🍏 This job's status is ${{ job.status }}."
|
||||||
|
|
||||||
- name: update version in the variable
|
- name: update version in the variable
|
||||||
run: |
|
run: |
|
||||||
curl -X PUT -H "Content-Type: application/json" \
|
curl -X PUT -H "Content-Type: application/json" \
|
||||||
--user ${{ secrets.USERNAME_GITEA }}:${{ secrets.PASSWORD_GITEA }} \
|
--user ${{ secrets.USERNAME_GITEA }}:${{ secrets.PASSWORD_GITEA }} \
|
||||||
https://gitea.tryton.geeraert.eu/api/v1/repos/pi-ux-ce/${{ github.event.repository.name }}/actions/variables/VERSION \
|
https://gitea.geeraert.eu/api/v1/repos/pi-ux-ce/${{ github.event.repository.name }}/actions/variables/VERSION \
|
||||||
-d "{\"Value\":\"$next_version\"}"
|
-d "{\"Value\":\"$next_version\"}"
|
||||||
|
|
||||||
- name: backup git for future use
|
- name: backup git for future use
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
name: Gitea Actions Demo
|
name: Dockerfile testing runner
|
||||||
run-name: ${{ gitea.actor }} is testing out Gitea Actions 🚀
|
run-name: Building and deploying to testing 🔎
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
branches:
|
branches:
|
||||||
- "testing"
|
- "testing"
|
||||||
paths:
|
paths:
|
||||||
- 'django_testing/dockerfile'
|
- 'infra/testing/dockerfile'
|
||||||
tags-ignore:
|
tags-ignore:
|
||||||
- '*'
|
- '*'
|
||||||
workflow_dispatch: # Enables the manual run UI button
|
workflow_dispatch: # Enables the manual run UI button
|
||||||
@@ -22,9 +22,6 @@ jobs:
|
|||||||
- name: List files in the repository
|
- name: List files in the repository
|
||||||
run: |
|
run: |
|
||||||
ls ${{ gitea.workspace }}
|
ls ${{ gitea.workspace }}
|
||||||
- name: Set up Docker Buildx
|
|
||||||
uses: docker/setup-buildx-action@v3
|
|
||||||
|
|
||||||
- name: Compute next version
|
- name: Compute next version
|
||||||
id: versioning
|
id: versioning
|
||||||
run: |
|
run: |
|
||||||
@@ -39,29 +36,31 @@ jobs:
|
|||||||
- name: Login to gitea
|
- name: Login to gitea
|
||||||
uses: docker/login-action@v3
|
uses: docker/login-action@v3
|
||||||
with:
|
with:
|
||||||
registry: gitea.tryton.geeraert.eu
|
registry: gitea.geeraert.eu
|
||||||
username: ${{ secrets.USERNAME_GITEA }}
|
username: ${{ secrets.USERNAME_GITEA }}
|
||||||
password: ${{ secrets.PASSWORD_GITEA }}
|
password: ${{ secrets.PASSWORD_GITEA }}
|
||||||
|
|
||||||
- name: Build and push
|
- name: Build image
|
||||||
uses: docker/build-push-action@v6
|
run: |
|
||||||
with:
|
docker build \
|
||||||
context: django_testing/
|
-f infra/testing/dockerfile \
|
||||||
push: true
|
--build-arg ALLOWED_HOSTS='django-testing.geeraert.eu' \
|
||||||
build-args: |
|
--build-arg DEBUG='True' \
|
||||||
ALLOWED_HOSTS='django-testing.tryton.geeraert.eu'
|
--build-arg CACHE_BUST=${{ env.next_version }} \
|
||||||
DEBUG='True'
|
-t gitea.geeraert.eu/pi-ux-ce/django-testing:latest \
|
||||||
tags: |
|
-t gitea.geeraert.eu/pi-ux-ce/django-testing:${{ env.next_version }} \
|
||||||
gitea.tryton.geeraert.eu/pi-ux-ce/django-testing:latest
|
.
|
||||||
gitea.tryton.geeraert.eu/pi-ux-ce/django-testing:${{ env.next_version }}
|
|
||||||
cache-from: type=registry,ref=gitea.tryton.geeraert.eu/pi-ux-ce/django-testing:buildcache
|
- name: Push image
|
||||||
cache-to: type=registry,ref=gitea.tryton.geeraert.eu/pi-ux-ce/django-testing:buildcache,mode=max
|
run: |
|
||||||
|
docker push gitea.geeraert.eu/pi-ux-ce/django-testing:latest
|
||||||
|
docker push gitea.geeraert.eu/pi-ux-ce/django-testing:${{ env.next_version }}
|
||||||
|
|
||||||
- name: update version in the variable
|
- name: update version in the variable
|
||||||
run: |
|
run: |
|
||||||
curl -X PUT -H "Content-Type: application/json" \
|
curl -X PUT -H "Content-Type: application/json" \
|
||||||
--user ${{ secrets.USERNAME_GITEA }}:${{ secrets.PASSWORD_GITEA }} \
|
--user ${{ secrets.USERNAME_GITEA }}:${{ secrets.PASSWORD_GITEA }} \
|
||||||
https://gitea.tryton.geeraert.eu/api/v1/repos/pi-ux-ce/${{ github.event.repository.name }}/actions/variables/VERSION_TESTING \
|
https://gitea.geeraert.eu/api/v1/repos/pi-ux-ce/${{ github.event.repository.name }}/actions/variables/VERSION_TESTING \
|
||||||
-d "{\"Value\":\"$next_version\"}"
|
-d "{\"Value\":\"$next_version\"}"
|
||||||
|
|
||||||
- name: Rollout Django to force pulling the new image
|
- name: Rollout Django to force pulling the new image
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
name: Gitea Actions Demo
|
name: Gitea Actions Demo
|
||||||
run-name: ${{ gitea.actor }} is testing out Gitea Actions 🚀
|
run-name: Deploying to Prod 🪂🛫
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
branches:
|
branches:
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
name: Gitea Actions Demo
|
name: Gitea Actions Demo
|
||||||
run-name: ${{ gitea.actor }} is testing out Gitea Actions 🚀
|
run-name: Deploying to testing 🏗️🧪
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
branches:
|
branches:
|
||||||
|
|||||||
@@ -226,3 +226,4 @@ __marimo__/
|
|||||||
Webcal-python/*
|
Webcal-python/*
|
||||||
.idea/*
|
.idea/*
|
||||||
django_code/db.sqlite3
|
django_code/db.sqlite3
|
||||||
|
|
||||||
|
|||||||
@@ -8,29 +8,62 @@ python django_code/manage.py makemigrations
|
|||||||
python django_code/manage.py makemigrations redirect
|
python django_code/manage.py makemigrations redirect
|
||||||
python django_code/manage.py makemigrations cloudmanager
|
python django_code/manage.py makemigrations cloudmanager
|
||||||
python django_code/manage.py makemigrations simpsons
|
python django_code/manage.py makemigrations simpsons
|
||||||
|
python django_code/manage.py makemigrations job
|
||||||
|
python django_code/manage.py makemigrations telegram
|
||||||
|
python django_code/manage.py makemigrations podcast
|
||||||
|
python django_code/manage.py makemigrations streaming
|
||||||
|
|
||||||
python django_code/manage.py migrate
|
python django_code/manage.py migrate
|
||||||
python django_code/manage.py migrate --database=cloudmanager_db
|
python django_code/manage.py migrate --database=cloudmanager_db
|
||||||
python django_code/manage.py migrate --database=simpsons_db
|
python django_code/manage.py migrate --database=simpsons_db
|
||||||
python django_code/manage.py migrate --database=redirect_db
|
python django_code/manage.py migrate --database=redirect_db
|
||||||
|
python django_code/manage.py migrate --database=job_db
|
||||||
|
python django_code/manage.py migrate --database=telegram_db
|
||||||
|
python django_code/manage.py migrate --database=podcast_db
|
||||||
|
python django_code/manage.py migrate --database=streaming_db
|
||||||
```
|
```
|
||||||
### Database debug
|
### Database debug
|
||||||
|
|
||||||
```
|
```
|
||||||
create database django;
|
create database django;
|
||||||
create database simpsons;
|
|
||||||
create database cloudmanager;
|
|
||||||
create database redirect;
|
create database redirect;
|
||||||
|
create database cloudmanager;
|
||||||
|
create database simpsons;
|
||||||
|
create database job;
|
||||||
|
create database telegram;
|
||||||
|
create database podcast;
|
||||||
|
create database streaming;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
drop database django;
|
|
||||||
drop database simpsons;
|
|
||||||
drop database cloudmanager;
|
|
||||||
drop database redirect;
|
drop database redirect;
|
||||||
|
drop database cloudmanager;
|
||||||
|
drop database simpsons;
|
||||||
|
drop database job;
|
||||||
|
drop database telegram;
|
||||||
|
drop database podcast;
|
||||||
|
drop database streaming;
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
### Setup virtualenv variables
|
||||||
|
edit venv/bin/activate or .env/bin/activate
|
||||||
|
|
||||||
|
and add the following code
|
||||||
|
```
|
||||||
|
export DB_HOST=localhost
|
||||||
|
export DB_PORT=5432
|
||||||
|
export DB_USERNAME=postgres
|
||||||
|
export DB_PASSWORD=example
|
||||||
|
export DB_DATABASE=cloudmanager
|
||||||
|
export CUSTOM_DB_DATABASE=cloudmanager
|
||||||
|
export ALLOWED_HOSTS="0.0.0.0,localhost,127.0.0.1"
|
||||||
|
export DEBUG=true
|
||||||
|
export bitwarden_access_token="PROVIDED IN BITWARDEN ADMIN INTERFACE"
|
||||||
|
export bitwarden_organization_id=""
|
||||||
```
|
```
|
||||||
|
|
||||||
To make it easy for you to get started with GitLab, here's a list of recommended next steps.
|
|
||||||
|
|
||||||
Already a pro? Just edit this README.md and make it your own. Want to make it easy? [Use the template at the bottom](#editing-this-readme)!
|
|
||||||
|
|
||||||
## Add your files
|
## Add your files
|
||||||
|
|
||||||
@@ -39,14 +72,14 @@ Already a pro? Just edit this README.md and make it your own. Want to make it ea
|
|||||||
|
|
||||||
```
|
```
|
||||||
cd existing_repo
|
cd existing_repo
|
||||||
git remote add origin https://gitlab.tryton.geeraert.eu/pierre/django_kube.git
|
git remote add origin https://gitea.geeraert.eu/pi-ux-ce/Django_kube.git
|
||||||
git branch -M main
|
git branch -M main
|
||||||
git push -uf origin main
|
git push -uf origin main
|
||||||
```
|
```
|
||||||
|
|
||||||
## Integrate with your tools
|
## Integrate with your tools
|
||||||
|
|
||||||
- [ ] [Set up project integrations](https://gitlab.tryton.geeraert.eu/pierre/django_kube/-/settings/integrations)
|
- [ ] [Set up project integrations](https://gitlab.geeraert.eu/pierre/django_kube/-/settings/integrations)
|
||||||
|
|
||||||
## Collaborate with your team
|
## Collaborate with your team
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,154 @@
|
|||||||
|
import requests
|
||||||
|
import hashlib
|
||||||
|
from apps.bitwarden.utils import bitwardenUtils
|
||||||
|
import os
|
||||||
|
|
||||||
|
class betaserieUtils():
|
||||||
|
url = "https://api.betaseries.com/members/auth"
|
||||||
|
|
||||||
|
username_UID="7bc7ebd2-9c95-487f-9ba2-b47301591ef0"
|
||||||
|
password_UID="262c3246-203b-44e0-854b-b47301599730"
|
||||||
|
token_UID="2cf4be0f-f26f-473f-b8f1-b473016139e4"
|
||||||
|
|
||||||
|
#Adding __ to make the variable private and can't be access outside the class,
|
||||||
|
# only by the class itself ot the subclass
|
||||||
|
|
||||||
|
__bitwarden_access_token = os.environ.get('bitwarden_access_token')
|
||||||
|
__bitwarden_organization_id = os.environ.get('bitwarden_organization_id')
|
||||||
|
|
||||||
|
bw = bitwardenUtils(__bitwarden_access_token,__bitwarden_organization_id)
|
||||||
|
|
||||||
|
__betaserie_username = bw.read_value_secret(username_UID)
|
||||||
|
__betaserie_md5_password = bw.read_value_secret(password_UID)
|
||||||
|
__betaserie_apikey = bw.read_value_secret(token_UID)
|
||||||
|
|
||||||
|
payload = {
|
||||||
|
'login': __betaserie_username, # username or email
|
||||||
|
'password': __betaserie_md5_password # MD5 hashed password
|
||||||
|
}
|
||||||
|
|
||||||
|
headers = {
|
||||||
|
'X-BetaSeries-Key': __betaserie_apikey,
|
||||||
|
}
|
||||||
|
response = requests.post(url, headers=headers, data=payload)
|
||||||
|
|
||||||
|
#now set with the correct value
|
||||||
|
__betaserie_token = response.json()['token']
|
||||||
|
|
||||||
|
#set the __betaserie_token to the doct headers now
|
||||||
|
headers.update({'X-BetaSeries-Token': __betaserie_token})
|
||||||
|
|
||||||
|
def status_code(self):
|
||||||
|
print("Status code:", self.response.status_code)
|
||||||
|
print("Response:", self.response.json())
|
||||||
|
|
||||||
|
|
||||||
|
def identify_serie(self,serie_name,verbose=False):
|
||||||
|
#
|
||||||
|
# Usage
|
||||||
|
# show_id = beta.identify_serie("The simpsons")
|
||||||
|
# show_id = beta.identify_serie("The simpsons",verbose=True)
|
||||||
|
#
|
||||||
|
url = "https://api.betaseries.com/shows/search?title="+serie_name
|
||||||
|
|
||||||
|
response = requests.request("GET", url, headers=self.headers, data=self.payload)
|
||||||
|
if verbose:
|
||||||
|
print("Url request: "+str(url))
|
||||||
|
print(response.text)
|
||||||
|
|
||||||
|
show_id = response.json()['shows'][0]['id']
|
||||||
|
|
||||||
|
return show_id
|
||||||
|
|
||||||
|
def poster_serie(self,serie_name,verbose=False):
|
||||||
|
#
|
||||||
|
# Usage
|
||||||
|
# poster_url = beta.poster_serie("The simpsons")
|
||||||
|
# poster_url = beta.poster_serie("The simpsons",verbose=True)
|
||||||
|
#
|
||||||
|
url = "https://api.betaseries.com/shows/search?title="+serie_name
|
||||||
|
|
||||||
|
response = requests.request("GET", url, headers=self.headers, data=self.payload)
|
||||||
|
if verbose:
|
||||||
|
print("Url request: "+str(url))
|
||||||
|
print(response.text)
|
||||||
|
|
||||||
|
poster_url = response.json()['shows'][0]['images']['show']
|
||||||
|
|
||||||
|
return poster_url
|
||||||
|
|
||||||
|
|
||||||
|
def identify_episode(self,show_id,episode_number,verbose=False):
|
||||||
|
#
|
||||||
|
# Usage
|
||||||
|
# episode_id,episode_seen = beta.identify_episode(show_id,"S01E01",True)
|
||||||
|
#
|
||||||
|
url = "https://api.betaseries.com/episodes/search?show_id="+str(show_id)+"&number="+str(episode_number)
|
||||||
|
|
||||||
|
response = requests.request("GET", url, headers=self.headers, data=self.payload)
|
||||||
|
|
||||||
|
episode_id = response.json()['episode']['id']
|
||||||
|
episode_seen = response.json()['episode']['user']['seen']
|
||||||
|
if verbose:
|
||||||
|
print("Url request: "+str(url))
|
||||||
|
print(response.text)
|
||||||
|
|
||||||
|
return episode_id,episode_seen
|
||||||
|
|
||||||
|
def mark_episodes_watched(self,episode_id,verbose=False):
|
||||||
|
#
|
||||||
|
# Usage
|
||||||
|
# response = beta.mark_episodes_watched(episode_id,True)
|
||||||
|
#
|
||||||
|
url = "https://api.betaseries.com/episodes/watched?id="+str(episode_id)+"&bulk=false"
|
||||||
|
|
||||||
|
response = requests.request("POST", url, headers=self.headers, data=self.payload)
|
||||||
|
if verbose:
|
||||||
|
print("Url request: "+str(url))
|
||||||
|
print(response.text)
|
||||||
|
|
||||||
|
return response.status_code
|
||||||
|
|
||||||
|
def unmark_episodes_watched(self,episode_id,verbose=False):
|
||||||
|
#
|
||||||
|
# Usage
|
||||||
|
# response = beta.unmark_episodes_watched(episode_id,True)
|
||||||
|
#
|
||||||
|
url = "https://api.betaseries.com/episodes/watched?id="+str(episode_id)
|
||||||
|
|
||||||
|
response = requests.request("DELETE", url, headers=self.headers, data=self.payload)
|
||||||
|
|
||||||
|
if verbose:
|
||||||
|
print("Url request: "+str(url))
|
||||||
|
print(response.text)
|
||||||
|
|
||||||
|
return response.status_code
|
||||||
|
|
||||||
|
def series_information(self,show_id,verbose=False):
|
||||||
|
#
|
||||||
|
# Usage
|
||||||
|
#
|
||||||
|
url = "https://api.betaseries.com/shows/display?id="+str(show_id)
|
||||||
|
response = requests.request("GET", url, headers=self.headers, data=self.payload)
|
||||||
|
|
||||||
|
seasons_details = response.json()['show']['seasons_details']
|
||||||
|
|
||||||
|
#checking if the first season is season 0, and if so remove this season
|
||||||
|
if (seasons_details[0]['number']==0):
|
||||||
|
season_0_to_remove = seasons_details[0]
|
||||||
|
|
||||||
|
if verbose : print(season_0_to_remove)
|
||||||
|
|
||||||
|
seasons_details.remove(season_0_to_remove)
|
||||||
|
|
||||||
|
maximum_number_seasons = len(seasons_details)
|
||||||
|
|
||||||
|
if verbose : print("maximum_number_seasons: "+str(maximum_number_seasons))
|
||||||
|
|
||||||
|
|
||||||
|
if verbose:
|
||||||
|
print("Url request: "+str(url))
|
||||||
|
print(response.text)
|
||||||
|
|
||||||
|
return seasons_details,maximum_number_seasons
|
||||||
|
|
||||||
@@ -0,0 +1,87 @@
|
|||||||
|
import logging
|
||||||
|
import os
|
||||||
|
from datetime import datetime, timezone
|
||||||
|
|
||||||
|
from bitwarden_sdk import BitwardenClient, DeviceType, client_settings_from_dict
|
||||||
|
|
||||||
|
|
||||||
|
class bitwardenUtils():
|
||||||
|
#documentation
|
||||||
|
#https://github.com/external-secrets/bitwarden-sdk-server
|
||||||
|
state_path = "/tmp/state_file.txt"
|
||||||
|
client = BitwardenClient(
|
||||||
|
client_settings_from_dict(
|
||||||
|
{
|
||||||
|
"apiUrl": os.getenv("API_URL", "https://bitwarden.geeraert.eu/api"),
|
||||||
|
"deviceType": DeviceType.SDK,
|
||||||
|
"identityUrl": os.getenv("IDENTITY_URL", "https://bitwarden.geeraert.eu/identity"),
|
||||||
|
"userAgent": "Python",
|
||||||
|
}
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
def verbose(self):
|
||||||
|
logging.basicConfig(level=logging.DEBUG)
|
||||||
|
|
||||||
|
|
||||||
|
def __init__(self, __access_token, __organization_id):
|
||||||
|
self.__access_token = __access_token
|
||||||
|
self.__organization_id = __organization_id
|
||||||
|
self.client.auth().login_access_token(self.__access_token, self.state_path)
|
||||||
|
|
||||||
|
def create_project(self,project_name):
|
||||||
|
project = self.client.projects().create(self.__organization_id, project_name)
|
||||||
|
return project.data.id
|
||||||
|
|
||||||
|
def generate_strong_password(self):
|
||||||
|
# Note: using the generator does not require authentication with a server
|
||||||
|
return self.client.generators().generate() # using default params
|
||||||
|
|
||||||
|
def create_secret(self,project_id,secret_name,secret_value,description="description"):
|
||||||
|
secret = self.client.secrets().create(
|
||||||
|
self.__organization_id,
|
||||||
|
secret_name,
|
||||||
|
secret_value,
|
||||||
|
description,
|
||||||
|
[project_id],
|
||||||
|
)
|
||||||
|
return secret.data.id
|
||||||
|
|
||||||
|
|
||||||
|
def read_value_secret(self,secret_id):
|
||||||
|
return self.client.secrets().get_by_ids([secret_id]).data.data[0].value
|
||||||
|
|
||||||
|
def read_value_secrets(self,list_secret_id):
|
||||||
|
if not(isinstance(list_secret_id, list)):
|
||||||
|
print("this is not a list")
|
||||||
|
return 1
|
||||||
|
list_secret_value = []
|
||||||
|
for secret_value in self.client.secrets().get_by_ids(list_secret_id).data.data:
|
||||||
|
list_secret_value.append(secret_value.value)
|
||||||
|
return list_secret_value
|
||||||
|
|
||||||
|
def delete_secrets(self,list_secret_id):
|
||||||
|
if not(isinstance(list_secret_id, list)):
|
||||||
|
print("this is not a list")
|
||||||
|
return 1
|
||||||
|
try:
|
||||||
|
self.client.secrets().delete(list_secret_id)
|
||||||
|
status=0
|
||||||
|
except:
|
||||||
|
print("Cannot delete the secrets")
|
||||||
|
status=1
|
||||||
|
return status
|
||||||
|
|
||||||
|
def delete_projects(self,list_project_id):
|
||||||
|
if not(isinstance(list_project_id, list)):
|
||||||
|
print("this is not a list")
|
||||||
|
return 1
|
||||||
|
try:
|
||||||
|
self.client.projects().delete(list_project_id)
|
||||||
|
status=0
|
||||||
|
except:
|
||||||
|
print("Cannot delete the project")
|
||||||
|
status=1
|
||||||
|
return status
|
||||||
|
|
||||||
|
|
||||||
@@ -1,10 +1,11 @@
|
|||||||
from django.contrib import admin,messages
|
from django.contrib import admin,messages
|
||||||
from django.utils.translation import ngettext
|
from django.utils.translation import ngettext
|
||||||
from .models import Deployment_Data,Schedule_Day_Data,Schedule_Week_Data,Namespace_Data,namespace_cmm_data_object
|
from .models import Deployment_Data,Schedule_Day_Data,Schedule_Week_Data,Namespace_Data,Ingress_Data
|
||||||
from .utils import import_namespace
|
from .utils import import_namespace,import_deployment,generate_default_day_schedule,generate_default_week_schedule,Check_server_supposed_XXX,retrieve_and_apply
|
||||||
from apps.kubernetes_connection.utils import scale_up,scale_down
|
from apps.kubernetes_connection.utils import scale_up,scale_down
|
||||||
|
from admin_extra_buttons.api import button
|
||||||
|
from core.admin import UniversalModelAdmin
|
||||||
|
|
||||||
DB = 'cloudmanager_db'
|
|
||||||
|
|
||||||
|
|
||||||
@admin.action(description="scale up")
|
@admin.action(description="scale up")
|
||||||
@@ -38,22 +39,18 @@ def scale_down_deploy(modeladmin, request, queryset):
|
|||||||
messages.SUCCESS,
|
messages.SUCCESS,
|
||||||
)
|
)
|
||||||
|
|
||||||
@admin.action(description="create_entry")
|
@admin.action(description="Expected False")
|
||||||
def create_entry(modeladmin, request, queryset):
|
def Check_server_supposed_False(modeladmin, request, queryset):
|
||||||
print("simpsons_data_object.create(season=2, episode=3, url='google.com'', seen=True)")
|
servers_supposed_false = Check_server_supposed_XXX(False)
|
||||||
#call function to trigger refresh of all deploy
|
for server in servers_supposed_false:
|
||||||
|
messages.add_message(request, messages.INFO, server)
|
||||||
@admin.action(description="import namespace")
|
|
||||||
def import_namespace_admin(modeladmin, request, queryset):
|
|
||||||
#
|
|
||||||
#
|
|
||||||
#
|
|
||||||
# don't forgot to clear thge quyeryset before running this
|
|
||||||
#
|
|
||||||
import_namespace(namespace_cmm_data_object)
|
|
||||||
print("simpsons_data_object.create(season=2, episode=3, url='google.com'', seen=True)")
|
|
||||||
#call function to trigger refresh of all deploy
|
|
||||||
|
|
||||||
|
@admin.action(description="Expected True")
|
||||||
|
def Check_server_supposed_true(modeladmin, request, queryset):
|
||||||
|
servers_supposed_false = Check_server_supposed_XXX(True)
|
||||||
|
for server in servers_supposed_false:
|
||||||
|
messages.add_message(request, messages.INFO, server)
|
||||||
|
|
||||||
|
|
||||||
class ActiveAtHourFilter(admin.SimpleListFilter):
|
class ActiveAtHourFilter(admin.SimpleListFilter):
|
||||||
title = 'Active at hour'
|
title = 'Active at hour'
|
||||||
@@ -69,44 +66,58 @@ class ActiveAtHourFilter(admin.SimpleListFilter):
|
|||||||
return queryset
|
return queryset
|
||||||
|
|
||||||
|
|
||||||
class MultiDBModelAdmin(admin.ModelAdmin):
|
|
||||||
"""Base class that pins all admin operations to DB."""
|
|
||||||
db = DB
|
|
||||||
|
|
||||||
def get_queryset(self, request):
|
|
||||||
return super().get_queryset(request).using(self.db)
|
|
||||||
|
|
||||||
def save_model(self, request, obj, form, change):
|
|
||||||
obj.save(using=self.db)
|
|
||||||
|
|
||||||
def delete_model(self, request, obj):
|
|
||||||
obj.delete(using=self.db)
|
|
||||||
|
|
||||||
def delete_queryset(self, request, queryset):
|
|
||||||
queryset.using(self.db).delete()
|
|
||||||
|
|
||||||
|
|
||||||
@admin.register(Deployment_Data)
|
@admin.register(Deployment_Data)
|
||||||
class DeploymentDataAdmin(MultiDBModelAdmin):
|
class DeploymentDataAdmin(UniversalModelAdmin):
|
||||||
list_display = ('name', 'namespace', 'schedule_week', 'schedule_day', 'replicas')
|
list_display = ('name', 'namespace', 'schedule_week', 'schedule_day', 'replicas')
|
||||||
list_filter = (ActiveAtHourFilter,)
|
list_filter = (ActiveAtHourFilter,)
|
||||||
actions = [scale_up_deploy,scale_down_deploy]
|
actions = [Check_server_supposed_False,Check_server_supposed_true,scale_up_deploy,scale_down_deploy]
|
||||||
|
ordering = ('name',)
|
||||||
|
@button()
|
||||||
|
def retrieve_and_apply(self, request):
|
||||||
|
# your business logic here
|
||||||
|
retrieve_and_apply()
|
||||||
|
self.message_user(request, 'Operation started')
|
||||||
|
|
||||||
|
@button()
|
||||||
|
def import_deployment(self, request):
|
||||||
|
# your business logic here
|
||||||
|
import_deployment()
|
||||||
|
self.message_user(request, 'Deployments imported')
|
||||||
|
|
||||||
@admin.register(Schedule_Day_Data)
|
@admin.register(Schedule_Day_Data)
|
||||||
class ScheduleDayAdmin(MultiDBModelAdmin):
|
class ScheduleDayAdmin(UniversalModelAdmin):
|
||||||
list_display = ['name_schedule'] + [f'state_at_{h}' for h in range(24)]
|
list_display = ['name_schedule'] + [f'state_at_{h}' for h in range(24)]
|
||||||
|
@button()
|
||||||
|
def generate_default_day_schedule_admin(self, request):
|
||||||
|
generate_default_day_schedule()
|
||||||
|
generate_default_week_schedule()
|
||||||
|
self.message_user(request, 'Created default schedules')
|
||||||
|
|
||||||
@admin.register(Schedule_Week_Data)
|
@admin.register(Schedule_Week_Data)
|
||||||
class ScheduleWeekAdmin(MultiDBModelAdmin):
|
class ScheduleWeekAdmin(UniversalModelAdmin):
|
||||||
list_display = (
|
list_display = (
|
||||||
'name_schedule',
|
'name_schedule',
|
||||||
'state_Monday', 'state_Tuesday', 'state_Wednesday',
|
'state_Monday', 'state_Tuesday', 'state_Wednesday',
|
||||||
'state_Thursday', 'state_Friday', 'state_Saturday', 'state_Sunday',
|
'state_Thursday', 'state_Friday', 'state_Saturday', 'state_Sunday',
|
||||||
)
|
)
|
||||||
|
@button()
|
||||||
|
def generate_default_day_schedule_admin(self, request):
|
||||||
|
generate_default_day_schedule()
|
||||||
|
generate_default_week_schedule()
|
||||||
|
self.message_user(request, 'Created default schedules')
|
||||||
|
|
||||||
|
|
||||||
@admin.register(Namespace_Data)
|
@admin.register(Namespace_Data)
|
||||||
class NamespaceAdmin(MultiDBModelAdmin):
|
class NamespaceAdmin(UniversalModelAdmin):
|
||||||
list_display = ('namespace',)
|
list_display = ('namespace',)
|
||||||
actions = [import_namespace_admin]
|
|
||||||
|
|
||||||
|
@button()
|
||||||
|
def import_namespace(self, request):
|
||||||
|
# your business logic here
|
||||||
|
import_namespace()
|
||||||
|
self.message_user(request, 'Namespaces imported')
|
||||||
|
|
||||||
|
@admin.register(Ingress_Data)
|
||||||
|
class IngressAdmin(UniversalModelAdmin):
|
||||||
|
list_display = ('url','namespace')
|
||||||
@@ -1,37 +1,6 @@
|
|||||||
from django.apps import AppConfig
|
from django.apps import AppConfig
|
||||||
from django.http import HttpResponse
|
|
||||||
from django.http import HttpResponseRedirect
|
|
||||||
from django.shortcuts import render
|
|
||||||
import os
|
|
||||||
import psycopg2
|
|
||||||
from apps.cloudmanager.db_interaction import DB_generation,Check_server_supposed_XXX,Give_current_weekday,Give_current_hour
|
|
||||||
|
|
||||||
|
|
||||||
class CloudmanagerConfig(AppConfig):
|
class CloudmanagerConfig(AppConfig):
|
||||||
default_auto_field = 'django.db.models.BigAutoField'
|
default_auto_field = 'django.db.models.BigAutoField'
|
||||||
name = 'apps.cloudmanager'
|
name = 'apps.cloudmanager'
|
||||||
label = 'cloudmanager'
|
label = 'cloudmanager'
|
||||||
|
|
||||||
def coucou(request):
|
|
||||||
return HttpResponse('<h1>Hello cmm!</h1>')
|
|
||||||
|
|
||||||
def hello(request):
|
|
||||||
list_schedule = ['schedule1','schedule2']
|
|
||||||
list_servers_up = [['wiki', 'wikijs', 2], ['book', 'bookstack-db', 1]]
|
|
||||||
return render(request, 'cloudmanager/index.html', {'list_schedule':list_schedule,'list_servers_up':list_servers_up})
|
|
||||||
|
|
||||||
def redirect(request):
|
|
||||||
db_host = os.environ.get('DB_HOST')
|
|
||||||
db_port = os.environ.get('DB_PORT')
|
|
||||||
db_user = os.environ.get('DB_USERNAME')
|
|
||||||
db_password = os.environ.get('DB_PASSWORD')
|
|
||||||
db_name = os.environ.get('CUSTOM_DB_DATABASE',os.environ.get('DB_DATABASE'))
|
|
||||||
|
|
||||||
generated_db = DB_generation(db_host, db_port, db_user, db_password,db_name)
|
|
||||||
##operation:
|
|
||||||
## Server(s) supposed to be UP
|
|
||||||
|
|
||||||
list_servers_up = Check_server_supposed_XXX(generated_db, "up", Give_current_hour(),Give_current_weekday())
|
|
||||||
print(list_servers_up)
|
|
||||||
return render(request, 'cloudmanager/cmm_blank_page.html', {'list_servers_up':list_servers_up})
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import psycopg2
|
#import psycopg2
|
||||||
from django.http import HttpResponse
|
from django.http import HttpResponse
|
||||||
from django.views.decorators.http import require_POST
|
from django.views.decorators.http import require_POST
|
||||||
from apps.kubernetes_connection import apps as kubernetes_connection
|
from apps.kubernetes_connection import apps as kubernetes_connection
|
||||||
@@ -153,10 +153,6 @@ def main(request):
|
|||||||
|
|
||||||
#print(Is_the_server_already_wanted_state(112, "stopped"))
|
#print(Is_the_server_already_wanted_state(112, "stopped"))
|
||||||
return HttpResponse('<h1>CMM executed!</h1>')
|
return HttpResponse('<h1>CMM executed!</h1>')
|
||||||
|
|
||||||
if __name__ == "__main__":
|
|
||||||
main()
|
|
||||||
|
|
||||||
|
|
||||||
"""
|
"""
|
||||||
TO DO:
|
TO DO:
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
# Generated by Django 4.2.30 on 2026-06-17 13:00
|
# Generated by Django 4.2.29 on 2026-06-22 20:21
|
||||||
|
|
||||||
from django.db import migrations, models
|
from django.db import migrations, models
|
||||||
import django.db.models.deletion
|
import django.db.models.deletion
|
||||||
@@ -12,6 +12,16 @@ class Migration(migrations.Migration):
|
|||||||
]
|
]
|
||||||
|
|
||||||
operations = [
|
operations = [
|
||||||
|
migrations.CreateModel(
|
||||||
|
name='Namespace_Data',
|
||||||
|
fields=[
|
||||||
|
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||||
|
('namespace', models.CharField(max_length=100)),
|
||||||
|
],
|
||||||
|
options={
|
||||||
|
'db_table': 'namespace',
|
||||||
|
},
|
||||||
|
),
|
||||||
migrations.CreateModel(
|
migrations.CreateModel(
|
||||||
name='Schedule_Day_Data',
|
name='Schedule_Day_Data',
|
||||||
fields=[
|
fields=[
|
||||||
@@ -64,7 +74,7 @@ class Migration(migrations.Migration):
|
|||||||
},
|
},
|
||||||
),
|
),
|
||||||
migrations.CreateModel(
|
migrations.CreateModel(
|
||||||
name='Machine_Data',
|
name='Deployment_Data',
|
||||||
fields=[
|
fields=[
|
||||||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||||
('name', models.CharField(max_length=100)),
|
('name', models.CharField(max_length=100)),
|
||||||
|
|||||||
@@ -0,0 +1,19 @@
|
|||||||
|
# Generated by Django 4.2.30 on 2026-09-09 12:48
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('cloudmanager', '0001_initial'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='deployment_data',
|
||||||
|
name='actual_replica',
|
||||||
|
field=models.IntegerField(default=1),
|
||||||
|
preserve_default=False,
|
||||||
|
),
|
||||||
|
]
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
# Generated by Django 4.2.29 on 2026-09-13 15:38
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('cloudmanager', '0002_deployment_data_actual_replica'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='deployment_data',
|
||||||
|
name='do_not_touch_until',
|
||||||
|
field=models.DateField(blank=True, null=True, verbose_name='do_not_touch_until'),
|
||||||
|
),
|
||||||
|
]
|
||||||
@@ -1,17 +0,0 @@
|
|||||||
# Generated by Django 4.2.30 on 2026-06-19 14:49
|
|
||||||
|
|
||||||
from django.db import migrations
|
|
||||||
|
|
||||||
|
|
||||||
class Migration(migrations.Migration):
|
|
||||||
|
|
||||||
dependencies = [
|
|
||||||
('cloudmanager', '0002_namespace_data'),
|
|
||||||
]
|
|
||||||
|
|
||||||
operations = [
|
|
||||||
migrations.RenameModel(
|
|
||||||
old_name='Machine_Data',
|
|
||||||
new_name='Deployment_Data',
|
|
||||||
),
|
|
||||||
]
|
|
||||||
+18
@@ -0,0 +1,18 @@
|
|||||||
|
# Generated by Django 4.2.30 on 2026-09-14 13:59
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('cloudmanager', '0003_deployment_data_do_not_touch_until'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='deployment_data',
|
||||||
|
name='do_not_touch_until',
|
||||||
|
field=models.DateTimeField(auto_now_add=True, null=True, verbose_name='do_not_touch_until'),
|
||||||
|
),
|
||||||
|
]
|
||||||
+19
@@ -0,0 +1,19 @@
|
|||||||
|
# Generated by Django 4.2.30 on 2026-09-14 14:14
|
||||||
|
|
||||||
|
import datetime
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('cloudmanager', '0004_alter_deployment_data_do_not_touch_until'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='deployment_data',
|
||||||
|
name='do_not_touch_until',
|
||||||
|
field=models.DateTimeField(default=datetime.datetime(2026, 9, 14, 14, 14, 29, 566084, tzinfo=datetime.timezone.utc), verbose_name='do_not_touch_until'),
|
||||||
|
),
|
||||||
|
]
|
||||||
+19
@@ -0,0 +1,19 @@
|
|||||||
|
# Generated by Django 4.2.30 on 2026-09-14 14:14
|
||||||
|
|
||||||
|
import datetime
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('cloudmanager', '0005_alter_deployment_data_do_not_touch_until'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='deployment_data',
|
||||||
|
name='do_not_touch_until',
|
||||||
|
field=models.DateTimeField(default=datetime.datetime(2026, 9, 14, 14, 14, 33, 642627, tzinfo=datetime.timezone.utc), verbose_name='do_not_touch_until'),
|
||||||
|
),
|
||||||
|
]
|
||||||
+19
@@ -0,0 +1,19 @@
|
|||||||
|
# Generated by Django 4.2.30 on 2026-09-14 14:35
|
||||||
|
|
||||||
|
import datetime
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('cloudmanager', '0006_alter_deployment_data_do_not_touch_until'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='deployment_data',
|
||||||
|
name='do_not_touch_until',
|
||||||
|
field=models.DateTimeField(default=datetime.datetime(2026, 9, 14, 14, 35, 47, 473312, tzinfo=datetime.timezone.utc), verbose_name='do_not_touch_until'),
|
||||||
|
),
|
||||||
|
]
|
||||||
+19
@@ -0,0 +1,19 @@
|
|||||||
|
# Generated by Django 4.2.30 on 2026-09-14 14:35
|
||||||
|
|
||||||
|
import datetime
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('cloudmanager', '0007_alter_deployment_data_do_not_touch_until'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='deployment_data',
|
||||||
|
name='do_not_touch_until',
|
||||||
|
field=models.DateTimeField(default=datetime.datetime(2026, 9, 14, 14, 35, 51, 657797, tzinfo=datetime.timezone.utc), verbose_name='do_not_touch_until'),
|
||||||
|
),
|
||||||
|
]
|
||||||
+19
@@ -0,0 +1,19 @@
|
|||||||
|
# Generated by Django 4.2.30 on 2026-09-14 14:43
|
||||||
|
|
||||||
|
import datetime
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('cloudmanager', '0008_alter_deployment_data_do_not_touch_until'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='deployment_data',
|
||||||
|
name='do_not_touch_until',
|
||||||
|
field=models.DateTimeField(default=datetime.datetime(2026, 9, 14, 14, 43, 26, 985719, tzinfo=datetime.timezone.utc), verbose_name='do_not_touch_until'),
|
||||||
|
),
|
||||||
|
]
|
||||||
+19
@@ -0,0 +1,19 @@
|
|||||||
|
# Generated by Django 4.2.30 on 2026-09-14 14:43
|
||||||
|
|
||||||
|
import datetime
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('cloudmanager', '0009_alter_deployment_data_do_not_touch_until'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='deployment_data',
|
||||||
|
name='do_not_touch_until',
|
||||||
|
field=models.DateTimeField(default=datetime.datetime(2026, 9, 14, 14, 43, 31, 55115, tzinfo=datetime.timezone.utc), verbose_name='do_not_touch_until'),
|
||||||
|
),
|
||||||
|
]
|
||||||
+18
@@ -0,0 +1,18 @@
|
|||||||
|
# Generated by Django 4.2.30 on 2026-09-14 14:46
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('cloudmanager', '0010_alter_deployment_data_do_not_touch_until'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='deployment_data',
|
||||||
|
name='do_not_touch_until',
|
||||||
|
field=models.DateTimeField(auto_now_add=True, null=True, verbose_name='do_not_touch_until'),
|
||||||
|
),
|
||||||
|
]
|
||||||
+19
@@ -0,0 +1,19 @@
|
|||||||
|
# Generated by Django 4.2.30 on 2026-09-14 15:13
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
import django.utils.timezone
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('cloudmanager', '0011_alter_deployment_data_do_not_touch_until'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='deployment_data',
|
||||||
|
name='do_not_touch_until',
|
||||||
|
field=models.DateTimeField(default=django.utils.timezone.now, verbose_name='do_not_touch_until'),
|
||||||
|
),
|
||||||
|
]
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
# Generated by Django 4.2.30 on 2026-09-21 16:14
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
import django.db.models.deletion
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('cloudmanager', '0012_alter_deployment_data_do_not_touch_until'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.CreateModel(
|
||||||
|
name='Ingress_Data',
|
||||||
|
fields=[
|
||||||
|
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||||
|
('url', models.CharField(max_length=100)),
|
||||||
|
('namespace', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to='cloudmanager.namespace_data')),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
]
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
# Generated by Django 4.2.30 on 2026-09-21 21:06
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('cloudmanager', '0013_ingress_data'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='ingress_data',
|
||||||
|
name='namespace',
|
||||||
|
field=models.CharField(blank=True, max_length=100, null=True),
|
||||||
|
),
|
||||||
|
]
|
||||||
@@ -1,6 +1,5 @@
|
|||||||
from django.db import models
|
from django.db import models
|
||||||
|
from django.utils import timezone
|
||||||
|
|
||||||
|
|
||||||
class Schedule_Week_Data(models.Model):
|
class Schedule_Week_Data(models.Model):
|
||||||
name_schedule = models.CharField(max_length=100,unique=True)
|
name_schedule = models.CharField(max_length=100,unique=True)
|
||||||
@@ -53,6 +52,8 @@ class Deployment_Data(models.Model):
|
|||||||
schedule_week = models.ForeignKey(Schedule_Week_Data,null=True, blank=True, on_delete=models.SET_NULL)
|
schedule_week = models.ForeignKey(Schedule_Week_Data,null=True, blank=True, on_delete=models.SET_NULL)
|
||||||
schedule_day = models.ForeignKey(Schedule_Day_Data,null=True, blank=True, on_delete=models.SET_NULL)
|
schedule_day = models.ForeignKey(Schedule_Day_Data,null=True, blank=True, on_delete=models.SET_NULL)
|
||||||
replicas = models.IntegerField()
|
replicas = models.IntegerField()
|
||||||
|
actual_replica = models.IntegerField()
|
||||||
|
do_not_touch_until = models.DateTimeField('do_not_touch_until', default=timezone.now)
|
||||||
class Meta:
|
class Meta:
|
||||||
db_table = 'machine'
|
db_table = 'machine'
|
||||||
|
|
||||||
@@ -61,5 +62,9 @@ class Namespace_Data(models.Model):
|
|||||||
#deployments = models.ForeignKey(Schedule_Week_Data,null=True, blank=True, on_delete=models.SET_NULL)
|
#deployments = models.ForeignKey(Schedule_Week_Data,null=True, blank=True, on_delete=models.SET_NULL)
|
||||||
class Meta:
|
class Meta:
|
||||||
db_table = 'namespace'
|
db_table = 'namespace'
|
||||||
|
def __str__(self):
|
||||||
|
return self.namespace
|
||||||
|
|
||||||
namespace_cmm_data_object = Namespace_Data.objects.using('cloudmanager_db')
|
class Ingress_Data(models.Model):
|
||||||
|
url = models.CharField(max_length=100)
|
||||||
|
namespace = models.CharField(max_length=100,null=True, blank=True)
|
||||||
|
|||||||
@@ -0,0 +1,33 @@
|
|||||||
|
"""
|
||||||
|
URL configuration for django_code project.
|
||||||
|
|
||||||
|
The `urlpatterns` list routes URLs to views. For more information please see:
|
||||||
|
https://docs.djangoproject.com/en/4.2/topics/http/urls/
|
||||||
|
Examples:
|
||||||
|
Function views
|
||||||
|
1. Add an import: from my_app import views
|
||||||
|
2. Add a URL to urlpatterns: path('', views.home, name='home')
|
||||||
|
Class-based views
|
||||||
|
1. Add an import: from other_app.views import Home
|
||||||
|
2. Add a URL to urlpatterns: path('', Home.as_view(), name='home')
|
||||||
|
Including another URLconf
|
||||||
|
1. Import the include() function: from django.urls import include, path
|
||||||
|
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
|
||||||
|
"""
|
||||||
|
from django.urls import path
|
||||||
|
|
||||||
|
from .views import hello,import_namespace_view,retrieve_and_apply_view,scale_up_gui,scale_down_gui,add_ingress,delete_ingress
|
||||||
|
|
||||||
|
|
||||||
|
urlpatterns = [
|
||||||
|
################### cloudmanager ###################
|
||||||
|
path('', hello, name='hello'),
|
||||||
|
path('import_namespace', import_namespace_view, name='import_namespace'),
|
||||||
|
path('retrieve_and_apply_view', retrieve_and_apply_view, name='retrieve_and_apply_view'),
|
||||||
|
path('scale_up/<str:namespace_name>/<str:deploy_name>', scale_up_gui),
|
||||||
|
path('scale_down/<str:namespace_name>/<str:deploy_name>', scale_down_gui),
|
||||||
|
path('add_ingress', add_ingress),
|
||||||
|
path('delete_ingress', delete_ingress),
|
||||||
|
|
||||||
|
|
||||||
|
]
|
||||||
@@ -1,13 +1,144 @@
|
|||||||
from apps.kubernetes_connection.utils import get_namespace
|
from django.utils import timezone
|
||||||
|
import datetime
|
||||||
|
from apps.kubernetes_connection.utils import get_namespace,get_deployments,scale_up,scale_down
|
||||||
|
from apps.cloudmanager.models import Schedule_Day_Data,Schedule_Week_Data,Namespace_Data,Deployment_Data
|
||||||
|
|
||||||
|
|
||||||
def import_namespace(queryset):
|
|
||||||
|
def import_namespace():
|
||||||
namespaces_list = get_namespace()
|
namespaces_list = get_namespace()
|
||||||
for namespace in namespaces_list:
|
for namespace in namespaces_list:
|
||||||
queryset.create(namespace=namespace)
|
if namespace[0]!="kube-system":
|
||||||
|
Namespace_Data.objects.get_or_create(namespace=namespace)
|
||||||
|
|
||||||
def import_deployment(queryset):
|
def import_deployment():
|
||||||
namespaces_list = get_namespace()
|
deployment_list = get_deployments()
|
||||||
#for namespace in namespaces_list:
|
Schedule_Day_Always_off,Schedule_Day_Always_on = generate_default_day_schedule()
|
||||||
# queryset.create(namespace=namespace)
|
Schedule_Week_Always_off,Schedule_Week_Always_on = generate_default_week_schedule()
|
||||||
|
|
||||||
|
for deployment in deployment_list:
|
||||||
|
#if the replicas is originally 0 , it means it is disabled so put the schedule as always off
|
||||||
|
if deployment[2] == 0:
|
||||||
|
schedule_object = Schedule_Day_Always_off
|
||||||
|
else:
|
||||||
|
schedule_object = Schedule_Day_Always_on
|
||||||
|
if deployment[0]!="kube-system":
|
||||||
|
Deployment_Data.objects.get_or_create(namespace=deployment[0],name=deployment[1],defaults={"replicas":deployment[2],"actual_replica":deployment[2],"schedule_day":schedule_object,"schedule_week":Schedule_Week_Always_on})
|
||||||
|
|
||||||
|
|
||||||
|
def generate_default_day_schedule():
|
||||||
|
Always_off,status = Schedule_Day_Data.objects.update_or_create(name_schedule="Always_off",defaults={"state_at_0" : False ,"state_at_1" : False ,"state_at_2" : False ,"state_at_3" : False ,"state_at_4" : False ,"state_at_5" : False ,"state_at_6" : False ,"state_at_7" : False ,"state_at_8" : False ,"state_at_9" : False ,"state_at_10" : False ,"state_at_11" : False ,"state_at_12" : False ,"state_at_13" : False ,"state_at_14" : False ,"state_at_15" : False ,"state_at_16" : False ,"state_at_17" : False ,"state_at_18" : False ,"state_at_19" : False ,"state_at_20" : False ,"state_at_21" : False ,"state_at_22" : False ,"state_at_23" : False})
|
||||||
|
Always_on,status = Schedule_Day_Data.objects.update_or_create(name_schedule="Always_on",defaults={"state_at_0" : True ,"state_at_1" : True ,"state_at_2" : True ,"state_at_3" : True ,"state_at_4" : True ,"state_at_5" : True ,"state_at_6" : True ,"state_at_7" : True ,"state_at_8" : True ,"state_at_9" : True ,"state_at_10" : True ,"state_at_11" : True ,"state_at_12" : True ,"state_at_13" : True ,"state_at_14" : True ,"state_at_15" : True ,"state_at_16" : True ,"state_at_17" : True ,"state_at_18" : True ,"state_at_19" : True ,"state_at_20" : True ,"state_at_21" : True ,"state_at_22" : True ,"state_at_23" : True})
|
||||||
|
return Always_off,Always_on
|
||||||
|
|
||||||
|
def generate_default_week_schedule():
|
||||||
|
Always_off,status = Schedule_Week_Data.objects.update_or_create(name_schedule="Always_off",defaults={"state_Monday" : False , "state_Tuesday" : False , "state_Wednesday" : False , "state_Thursday" : False , "state_Friday" : False , "state_Saturday" : False , "state_Sunday" : False})
|
||||||
|
Always_on,status = Schedule_Week_Data.objects.update_or_create(name_schedule="Always_on",defaults={"state_Monday" : True , "state_Tuesday" : True , "state_Wednesday" : True , "state_Thursday" : True , "state_Friday" : True , "state_Saturday" : True , "state_Sunday" : True})
|
||||||
|
return Always_off,Always_on
|
||||||
|
|
||||||
|
def Give_current_weekday():
|
||||||
|
days = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday','Saturday', 'Sunday']
|
||||||
|
weekday = days[datetime.datetime.today().weekday()]
|
||||||
|
return weekday
|
||||||
|
|
||||||
|
def Give_current_hour():
|
||||||
|
now = datetime.datetime.now()
|
||||||
|
return now.hour
|
||||||
|
|
||||||
|
def get_current_replicas():
|
||||||
|
deployments_list = get_deployments()
|
||||||
|
for deployment in deployments_list:
|
||||||
|
if deployment[0]!="kube-system":
|
||||||
|
object,created = Deployment_Data.objects.update_or_create(namespace=deployment[0],name=deployment[1],defaults={"actual_replica":deployment[2]})
|
||||||
|
if created:
|
||||||
|
print("THIS DEPLOY: name: "+str(server[1])+" namespace: "+str(server[0])+" replicas: "+str(server[2])+" IS NEW !!!!!")
|
||||||
|
return 0
|
||||||
|
|
||||||
|
def Check_server_supposed_XXX(expected_status,verbose=False):
|
||||||
|
#just for testing
|
||||||
|
#expected_status = True
|
||||||
|
|
||||||
|
# Get week schedule
|
||||||
|
|
||||||
|
argument_week="state_"+str(Give_current_weekday())
|
||||||
|
query_week = {argument_week : expected_status}
|
||||||
|
|
||||||
|
schedules_week = Schedule_Week_Data.objects.filter(**query_week)
|
||||||
|
|
||||||
|
# Get day schedule
|
||||||
|
|
||||||
|
argument_day="state_at_"+str(Give_current_hour())
|
||||||
|
query_day = {argument_day : expected_status}
|
||||||
|
|
||||||
|
schedules_day = Schedule_Day_Data.objects.filter(**query_day)
|
||||||
|
|
||||||
|
if expected_status:
|
||||||
|
deployments = Deployment_Data.objects.filter(schedule_week__in=schedules_week, schedule_day__in=schedules_day)
|
||||||
|
else:
|
||||||
|
deployments = Deployment_Data.objects.filter(schedule_week__in=schedules_week) | Deployment_Data.objects.filter(schedule_day__in=schedules_day)
|
||||||
|
|
||||||
|
deployments_list = []
|
||||||
|
for deployment in deployments:
|
||||||
|
display_list = []
|
||||||
|
name = deployment.name
|
||||||
|
display_list.append(name)
|
||||||
|
if verbose : print("name: "+str(name))
|
||||||
|
namespace = deployment.namespace
|
||||||
|
display_list.append(namespace)
|
||||||
|
if verbose : print("namespace: "+str(namespace))
|
||||||
|
replicas = deployment.replicas
|
||||||
|
display_list.append(replicas)
|
||||||
|
if verbose : print("replicas: "+str(replicas))
|
||||||
|
#Adding the whole object as well for future use
|
||||||
|
display_list.append(deployment)
|
||||||
|
deployments_list.append(display_list)
|
||||||
|
|
||||||
|
return deployments_list
|
||||||
|
|
||||||
|
|
||||||
|
def retrieve_and_apply(verbose=False):
|
||||||
|
output = ""
|
||||||
|
output += str(Give_current_hour())
|
||||||
|
output += str("\n")
|
||||||
|
|
||||||
|
|
||||||
|
#Get current replica to compare with the replicas created at the start
|
||||||
|
get_current_replicas()
|
||||||
|
|
||||||
|
print("------------------------------------------")
|
||||||
|
print("-----------------UP-----------------------")
|
||||||
|
print("------------------------------------------")
|
||||||
|
servers_supposed_true = Check_server_supposed_XXX(True)
|
||||||
|
for server in servers_supposed_true:
|
||||||
|
#check if the expected replica (server[2]) match the current replica of the deployment (server[3].actual_replica)
|
||||||
|
if server[3].actual_replica == server[2]:
|
||||||
|
if verbose : print("name: "+str(server[1])+" namespace: "+str(server[0])+" already UP")
|
||||||
|
elif server[3].do_not_touch_until > timezone.now():
|
||||||
|
if verbose : print("name: "+str(server[1])+" namespace: "+str(server[0])+" is in freeze period")
|
||||||
|
else:
|
||||||
|
echo = "Starting -> name: "+str(server[1])+" namespace: "+str(server[0])+" replicas: "+str(server[2])
|
||||||
|
output += str(echo)
|
||||||
|
output += "\n"
|
||||||
|
print(echo)
|
||||||
|
|
||||||
|
scale_up(namespace_name=server[1],deploy_name=server[0],replicas=server[2])
|
||||||
|
|
||||||
|
print("------------------------------------------")
|
||||||
|
print("----------------DOWN----------------------")
|
||||||
|
print("------------------------------------------")
|
||||||
|
servers_supposed_false = Check_server_supposed_XXX(False)
|
||||||
|
for server in servers_supposed_false:
|
||||||
|
#check if the current replica of the deployment (server[3].actual_replica) is already 0 meaning the server is already down
|
||||||
|
if server[3].actual_replica == 0:
|
||||||
|
if verbose : print("name: "+str(server[1])+" namespace: "+str(server[0])+" already DOWN")
|
||||||
|
elif server[3].do_not_touch_until > timezone.now():
|
||||||
|
if verbose : print("name: "+str(server[1])+" namespace: "+str(server[0])+" is in freeze period")
|
||||||
|
else:
|
||||||
|
|
||||||
|
echo = "Shutting down -> name: "+str(server[1])+" namespace: "+str(server[0])+" replicas: "+str(server[2])
|
||||||
|
output += str(echo)
|
||||||
|
output += str("\n")
|
||||||
|
print(echo)
|
||||||
|
scale_down(namespace_name=server[1],deploy_name=server[0])
|
||||||
|
print("------------------------------------------")
|
||||||
|
return output
|
||||||
@@ -1,25 +1,77 @@
|
|||||||
from django.http import HttpResponse
|
from django.http import HttpResponse
|
||||||
|
from django.shortcuts import render
|
||||||
|
from datetime import timedelta
|
||||||
|
from django.utils import timezone
|
||||||
|
from django.views.decorators.csrf import csrf_exempt
|
||||||
|
from django.http import JsonResponse
|
||||||
|
|
||||||
# IMPORT AT THE TOP HERE: This is completely safe!
|
from apps.import_aggregator.import_rest_framework import api_view, authentication_classes, permission_classes,TokenAuthentication,IsAuthenticated,Response,status
|
||||||
from apps.cloudmanager.models import Deployment_Data,Schedule_Week_Data
|
|
||||||
|
|
||||||
def coucou(request):
|
from .utils import import_namespace,retrieve_and_apply
|
||||||
# 1. Prepare the data inside the function
|
from apps.kubernetes_connection.utils import scale_up,scale_down
|
||||||
data = CmmData(
|
from .models import Deployment_Data,Ingress_Data
|
||||||
name="test",
|
|
||||||
namespace="testspace",
|
|
||||||
schedule_hour="1",
|
|
||||||
schedule_day="deux",
|
|
||||||
replicas=3
|
|
||||||
)
|
|
||||||
|
|
||||||
# 2. This line actually pushes the data into your cloudmanager_db!
|
def hello(request):
|
||||||
data.save()
|
list_schedule = ['schedule1','schedule2']
|
||||||
|
list_servers_up = [['wiki', 'wikijs', 2], ['book', 'bookstack-db', 1]]
|
||||||
|
return render(request, 'cloudmanager/index.html', {'list_schedule':list_schedule,'list_servers_up':list_servers_up})
|
||||||
|
|
||||||
return HttpResponse('<h1>Hello cmm! Data saved successfully!</h1>')
|
def import_namespace_view(request):
|
||||||
|
import_namespace()
|
||||||
|
return HttpResponse('<h1>Namespace imported!</h1>')
|
||||||
|
|
||||||
def display(request):
|
|
||||||
data = CmmData.objects.all()
|
|
||||||
print(data[0].namespace)
|
|
||||||
return HttpResponse(data)
|
|
||||||
|
|
||||||
|
def retrieve_and_apply_view(request):
|
||||||
|
output = retrieve_and_apply()
|
||||||
|
return HttpResponse('<h1>'+output+'</h1>')
|
||||||
|
|
||||||
|
def scale_up_gui(request,namespace_name,deploy_name,replicas=1):
|
||||||
|
Deployment_Data.objects.filter(namespace=namespace_name,name=deploy_name).update(do_not_touch_until=timezone.now() + timedelta(hours=1))
|
||||||
|
scale_up(namespace_name=namespace_name,deploy_name=deploy_name,replicas=replicas)
|
||||||
|
return render(request, 'dashboard/start.html', {'namespace':namespace_name,'deployment': deploy_name, 'url': 'https://namespace.com'})
|
||||||
|
|
||||||
|
|
||||||
|
def scale_down_gui(request,namespace_name,deploy_name):
|
||||||
|
Deployment_Data.objects.filter(namespace=namespace_name,name=deploy_name).update(do_not_touch_until=timezone.now() + timedelta(hours=1))
|
||||||
|
scale_down(namespace_name=namespace_name,deploy_name=deploy_name)
|
||||||
|
return render(request, 'dashboard/shutdown.html',
|
||||||
|
{'namespace': namespace_name, 'deployment': deploy_name, 'url': 'https://namespace.com'})
|
||||||
|
|
||||||
|
|
||||||
|
@api_view(['POST'])
|
||||||
|
@authentication_classes([TokenAuthentication])
|
||||||
|
@permission_classes([IsAuthenticated])
|
||||||
|
def add_ingress(request):
|
||||||
|
url = request.POST.get('url')
|
||||||
|
namespace = request.POST.get('namespace')
|
||||||
|
print("URL: "+str(url))
|
||||||
|
print("NS: "+str(namespace))
|
||||||
|
|
||||||
|
try:
|
||||||
|
Ingress_Data.objects.update_or_create(url=url,namespace=namespace)
|
||||||
|
except Exception as exception:
|
||||||
|
return JsonResponse({"status": "error","reason":str(exception)})
|
||||||
|
|
||||||
|
return JsonResponse({"status": "added","url":str(url),"namespace":str(namespace)})
|
||||||
|
|
||||||
|
@api_view(['POST'])
|
||||||
|
@authentication_classes([TokenAuthentication])
|
||||||
|
@permission_classes([IsAuthenticated])
|
||||||
|
def delete_ingress(request):
|
||||||
|
url = request.POST.get('url')
|
||||||
|
namespace = request.POST.get('namespace')
|
||||||
|
print("URL: "+str(url))
|
||||||
|
print("NS: "+str(namespace))
|
||||||
|
|
||||||
|
try:
|
||||||
|
ingress_object = Ingress_Data.objects.filter(url=url,namespace=namespace)
|
||||||
|
except Exception as exception:
|
||||||
|
return JsonResponse({"status": "error","reason":str(exception)})
|
||||||
|
|
||||||
|
try:
|
||||||
|
ingress_object.delete()
|
||||||
|
except Exception as exception:
|
||||||
|
return JsonResponse({"status": "error","reason":str(exception)})
|
||||||
|
|
||||||
|
return JsonResponse({"status": "deleted","url":str(url),"namespace":str(namespace)})
|
||||||
|
|
||||||
@@ -1,3 +0,0 @@
|
|||||||
from django.contrib import admin
|
|
||||||
|
|
||||||
# Register your models here.
|
|
||||||
@@ -1,46 +0,0 @@
|
|||||||
from django.apps import AppConfig
|
|
||||||
from django.http import HttpResponse
|
|
||||||
from django.shortcuts import render
|
|
||||||
import requests
|
|
||||||
from proxmoxer import ProxmoxAPI
|
|
||||||
import docker
|
|
||||||
|
|
||||||
class BackofficeConfig(AppConfig):
|
|
||||||
default_auto_field = 'django.db.models.BigAutoField'
|
|
||||||
name = 'backoffice'
|
|
||||||
|
|
||||||
def hello(request):
|
|
||||||
return HttpResponse('<h1>Start bookstack!</h1>')
|
|
||||||
|
|
||||||
def http_call_test(request):
|
|
||||||
url = 'http://portainer.zeus.geeraert.eu/api/auth/'
|
|
||||||
myobj = {'Username': 'admin','Password':'Xtm78*CX3mJ54g'}
|
|
||||||
|
|
||||||
x = requests.post(url, json = myobj)
|
|
||||||
|
|
||||||
print(x.text)
|
|
||||||
return HttpResponse(x.text)
|
|
||||||
|
|
||||||
def proxmox(request):
|
|
||||||
proxmox = ProxmoxAPI("proxmox.zeus.geeraert.eu", user="root@pam", password="dinner_sl@v3", verify_ssl=False)
|
|
||||||
return HttpResponse(proxmox)
|
|
||||||
|
|
||||||
def docker_call(request,action,id_docker):
|
|
||||||
print(action)
|
|
||||||
print(id_docker)
|
|
||||||
client = docker.from_env()
|
|
||||||
if action == "start":
|
|
||||||
print("nous allons start")
|
|
||||||
client.containers.get(id_docker).start()
|
|
||||||
if action == "stop":
|
|
||||||
print("nous allons stop")
|
|
||||||
client.containers.get(id_docker).stop()
|
|
||||||
|
|
||||||
return HttpResponse(client.containers.get(id_docker).status)
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -1,3 +0,0 @@
|
|||||||
from django.db import models
|
|
||||||
|
|
||||||
# Create your models here.
|
|
||||||
@@ -1,8 +0,0 @@
|
|||||||
from django.shortcuts import render
|
|
||||||
|
|
||||||
# Create your views here.
|
|
||||||
from django.http import HttpResponse
|
|
||||||
from django.shortcuts import render
|
|
||||||
|
|
||||||
def hello(request):
|
|
||||||
return HttpResponse('<h1>Hello Django!</h1>')
|
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
from rest_framework.decorators import api_view, authentication_classes, permission_classes
|
||||||
|
from rest_framework.authentication import TokenAuthentication
|
||||||
|
from rest_framework.permissions import IsAuthenticated
|
||||||
|
from rest_framework.response import Response
|
||||||
|
from rest_framework import status
|
||||||
|
|
||||||
@@ -0,0 +1,40 @@
|
|||||||
|
from django.contrib import admin
|
||||||
|
from import_export import resources
|
||||||
|
from import_export.fields import Field
|
||||||
|
from .models import JobData
|
||||||
|
from django.utils.text import Truncator
|
||||||
|
from core.admin import UniversalModelAdmin
|
||||||
|
|
||||||
|
# Register your models here.
|
||||||
|
|
||||||
|
|
||||||
|
class JobResource(resources.ModelResource):
|
||||||
|
# Map 'csv_column_name' from the file to 'model_variable_name' in your DB
|
||||||
|
job_position = Field(attribute='job_position',column_name='Job Position')
|
||||||
|
company = Field(attribute='company',column_name='Company')
|
||||||
|
URL = Field(attribute='URL',column_name='URL')
|
||||||
|
status = Field(attribute='status',column_name='Status')
|
||||||
|
date_saved = Field(attribute='date_saved',column_name='Date Saved')
|
||||||
|
date_applied = Field(attribute='date_applied',column_name='Date Applied')
|
||||||
|
type = Field(attribute='type',column_name='Type')
|
||||||
|
resume = Field(attribute='resume',column_name='Resume')
|
||||||
|
#cover_letter = Field(attribute='cover_letter',column_name='Cover Letter')
|
||||||
|
location = Field(attribute='location',column_name='Location')
|
||||||
|
job_description = Field(attribute='job_description',column_name='Job Description')
|
||||||
|
salary = Field(attribute='salary',column_name='Salary')
|
||||||
|
contact = Field(attribute='contact',column_name='Contact')
|
||||||
|
source = Field(attribute='source',column_name='Source')
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
model = JobData
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@admin.register(JobData)
|
||||||
|
class JobAdmin(UniversalModelAdmin):
|
||||||
|
list_display = ('job_position','company','URL','status','date_saved','date_applied','type','resume','location','short_description','salary','contact','source')
|
||||||
|
#fields = ['job_position','company','URL','status','date_saved','date_applied','type','resume','cover_letter','location','job_description','salary ','contact','source']
|
||||||
|
resource_classes = [JobResource]
|
||||||
|
def short_description(self, obj):
|
||||||
|
return Truncator(obj.job_description).words(10, truncate=' ...')
|
||||||
|
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
from django.apps import AppConfig
|
||||||
|
|
||||||
|
class JobDashboardConfig(AppConfig):
|
||||||
|
default_auto_field = 'django.db.models.BigAutoField'
|
||||||
|
name = 'apps.job_dashboard'
|
||||||
|
label = 'job'
|
||||||
@@ -0,0 +1,36 @@
|
|||||||
|
# Generated by Django 4.2.29 on 2026-06-22 20:21
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
initial = True
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.CreateModel(
|
||||||
|
name='JobData',
|
||||||
|
fields=[
|
||||||
|
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||||
|
('job_position', models.CharField(max_length=100, null=True)),
|
||||||
|
('company', models.CharField(max_length=100, null=True)),
|
||||||
|
('URL', models.URLField(max_length=1000, null=True)),
|
||||||
|
('status', models.CharField(choices=[('Rejected', 'Rejected'), ('Applied', 'Applied'), ('Negotiating', 'Negotiating'), ('Bookmarked', 'Bookmarked'), ('Accepted', 'Accepted')], max_length=100, null=True)),
|
||||||
|
('date_saved', models.CharField(max_length=100, null=True)),
|
||||||
|
('date_applied', models.CharField(max_length=100, null=True)),
|
||||||
|
('type', models.CharField(max_length=100, null=True)),
|
||||||
|
('resume', models.URLField(null=True)),
|
||||||
|
('location', models.CharField(max_length=100, null=True)),
|
||||||
|
('job_description', models.CharField(null=True)),
|
||||||
|
('salary', models.CharField(null=True)),
|
||||||
|
('contact', models.CharField(max_length=100, null=True)),
|
||||||
|
('source', models.CharField(max_length=100, null=True)),
|
||||||
|
],
|
||||||
|
options={
|
||||||
|
'db_table': 'job',
|
||||||
|
},
|
||||||
|
),
|
||||||
|
]
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
from django.db import models
|
||||||
|
|
||||||
|
|
||||||
|
status_CHOICES = (
|
||||||
|
('Rejected','Rejected'),
|
||||||
|
('Applied','Applied'),
|
||||||
|
('Negotiating','Negotiating'),
|
||||||
|
('Bookmarked','Bookmarked'),
|
||||||
|
('Accepted','Accepted')
|
||||||
|
)
|
||||||
|
|
||||||
|
class JobData(models.Model):
|
||||||
|
job_position = models.CharField(max_length=100, null=True)
|
||||||
|
company = models.CharField(max_length=100, null=True)
|
||||||
|
URL = models.URLField(max_length=1000,null=True)
|
||||||
|
status = models.CharField(max_length=100,choices=status_CHOICES, null=True)
|
||||||
|
date_saved = models.CharField(max_length=100, null=True)
|
||||||
|
date_applied = models.CharField(max_length=100, null=True)
|
||||||
|
type = models.CharField(max_length=100, null=True)
|
||||||
|
resume = models.URLField(max_length=200, null=True)
|
||||||
|
#cover_letter = models.URLField(max_length=200, null=True)
|
||||||
|
location = models.CharField(max_length=100, null=True)
|
||||||
|
job_description = models.CharField(null=True)
|
||||||
|
salary = models.CharField(null=True)
|
||||||
|
contact = models.CharField(max_length=100, null=True)
|
||||||
|
source = models.CharField(max_length=100, null=True)
|
||||||
|
class Meta:
|
||||||
|
db_table = 'job'
|
||||||
|
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
"""
|
||||||
|
URL configuration for django_code project.
|
||||||
|
|
||||||
|
The `urlpatterns` list routes URLs to views. For more information please see:
|
||||||
|
https://docs.djangoproject.com/en/4.2/topics/http/urls/
|
||||||
|
Examples:
|
||||||
|
Function views
|
||||||
|
1. Add an import: from my_app import views
|
||||||
|
2. Add a URL to urlpatterns: path('', views.home, name='home')
|
||||||
|
Class-based views
|
||||||
|
1. Add an import: from other_app.views import Home
|
||||||
|
2. Add a URL to urlpatterns: path('', Home.as_view(), name='home')
|
||||||
|
Including another URLconf
|
||||||
|
1. Import the include() function: from django.urls import include, path
|
||||||
|
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
|
||||||
|
"""
|
||||||
|
from django.urls import path
|
||||||
|
from django.contrib import admin
|
||||||
|
|
||||||
|
urlpatterns = [
|
||||||
|
path('', admin.site.urls),
|
||||||
|
]
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
from django.shortcuts import render
|
||||||
|
|
||||||
|
# Create your views here.
|
||||||
@@ -62,7 +62,7 @@ def nodes(request):
|
|||||||
'spec': {
|
'spec': {
|
||||||
|
|
||||||
'containers': [{
|
'containers': [{
|
||||||
'image': 'gitea.tryton.geeraert.eu/pi-ux-ce/bitwarden_cli:1.0.1',
|
'image': 'gitea.geeraert.eu/pi-ux-ce/bitwarden_cli:1.0.1',
|
||||||
# 'pod-running-timeout': '5m0s',
|
# 'pod-running-timeout': '5m0s',
|
||||||
'name': 'testpython',
|
'name': 'testpython',
|
||||||
'env': [
|
'env': [
|
||||||
@@ -96,7 +96,7 @@ def backup_job(request):
|
|||||||
'spec': {
|
'spec': {
|
||||||
|
|
||||||
'containers': [{
|
'containers': [{
|
||||||
'image': 'gitea.tryton.geeraert.eu/pi-ux-ce/bitwarden_cli:1.0.1',
|
'image': 'gitea.geeraert.eu/pi-ux-ce/bitwarden_cli:1.0.1',
|
||||||
'name': 'testpython',
|
'name': 'testpython',
|
||||||
'command': ['/bin/sh -c /config/export_bitwarden.sh'],
|
'command': ['/bin/sh -c /config/export_bitwarden.sh'],
|
||||||
'env': [
|
'env': [
|
||||||
@@ -124,8 +124,8 @@ def backup_job_yaml(request,sync_target):
|
|||||||
v1 = client.BatchV1Api()
|
v1 = client.BatchV1Api()
|
||||||
|
|
||||||
yaml_location = {
|
yaml_location = {
|
||||||
"synology" : "https://gitea.tryton.geeraert.eu/pi-ux-ce/Backup_kube/raw/branch/main/Infrequent_access/synology_pod.yaml",
|
"synology" : "https://gitea.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"
|
"openmediavault":"https://gitea.geeraert.eu/pi-ux-ce/Backup_kube/raw/branch/main/Infrequent_access/openmediavault_pod.yaml"
|
||||||
}
|
}
|
||||||
print(yaml_location[sync_target])
|
print(yaml_location[sync_target])
|
||||||
url_to_select=yaml_location[sync_target]
|
url_to_select=yaml_location[sync_target]
|
||||||
|
|||||||
@@ -0,0 +1,29 @@
|
|||||||
|
"""
|
||||||
|
URL configuration for django_code project.
|
||||||
|
|
||||||
|
The `urlpatterns` list routes URLs to views. For more information please see:
|
||||||
|
https://docs.djangoproject.com/en/4.2/topics/http/urls/
|
||||||
|
Examples:
|
||||||
|
Function views
|
||||||
|
1. Add an import: from my_app import views
|
||||||
|
2. Add a URL to urlpatterns: path('', views.home, name='home')
|
||||||
|
Class-based views
|
||||||
|
1. Add an import: from other_app.views import Home
|
||||||
|
2. Add a URL to urlpatterns: path('', Home.as_view(), name='home')
|
||||||
|
Including another URLconf
|
||||||
|
1. Import the include() function: from django.urls import include, path
|
||||||
|
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
|
||||||
|
"""
|
||||||
|
from django.urls import path
|
||||||
|
from apps.kubernetes_connection import apps as kubernetes_connection
|
||||||
|
|
||||||
|
urlpatterns = [
|
||||||
|
################## kubernetes_connection#####
|
||||||
|
path('hello/', kubernetes_connection.hello),
|
||||||
|
path('nodes/', kubernetes_connection.nodes),
|
||||||
|
path('backup_job/', kubernetes_connection.backup_job),
|
||||||
|
path('backup_job_yaml/', kubernetes_connection.backup_job_yaml),
|
||||||
|
path('scale_up/<str:namespace_name>/<str:deploy_name>', kubernetes_connection.scale_up),
|
||||||
|
path('scale_down/<str:namespace_name>/<str:deploy_name>', kubernetes_connection.scale_down),
|
||||||
|
|
||||||
|
]
|
||||||
@@ -32,26 +32,27 @@ def import_Deployments():
|
|||||||
test.items[2].spec.template.spec.containers[0].name # name the third deploy within the namespace
|
test.items[2].spec.template.spec.containers[0].name # name the third deploy within the namespace
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
def get_namespace():
|
def get_namespace(verbose=False):
|
||||||
config.load_kube_config(config_file='/kubeconfig/config')
|
config.load_kube_config(config_file='/kubeconfig/config')
|
||||||
core = client.CoreV1Api()
|
core = client.CoreV1Api()
|
||||||
namespace = core.list_namespace()
|
namespace = core.list_namespace()
|
||||||
namespace_list = []
|
namespace_list = []
|
||||||
for i in range(0,len(namespace.items)):
|
for i in range(0,len(namespace.items)):
|
||||||
print(namespace.items[i].metadata.name)
|
if verbose : print(namespace.items[i].metadata.name)
|
||||||
namespace_list.append(namespace.items[i].metadata.name)
|
namespace_list.append(namespace.items[i].metadata.name)
|
||||||
return namespace_list
|
return namespace_list
|
||||||
|
|
||||||
def get_deployments():
|
def get_deployments(verbose=False):
|
||||||
config.load_kube_config(config_file='/kubeconfig/config')
|
config.load_kube_config(config_file='/kubeconfig/config')
|
||||||
api = client.AppsV1Api()
|
api = client.AppsV1Api()
|
||||||
namespaces_list = get_namespace()
|
namespaces_list = get_namespace()
|
||||||
deployments_list = []
|
deployments_list = []
|
||||||
for namespace in namespaces_list:
|
for namespace in namespaces_list:
|
||||||
print(namespace)
|
if verbose : print(namespace)
|
||||||
deployments = api.list_namespaced_deployment(namespace)
|
deployments = api.list_namespaced_deployment(namespace)
|
||||||
for deployment_index in range(0,len(deployments.items)):
|
for deployment_index in range(0,len(deployments.items)):
|
||||||
deployment = deployments.items[deployment_index].metadata.name
|
deployment = deployments.items[deployment_index].metadata.name
|
||||||
print(" "+str(deployment))
|
replicas = deployments.items[deployment_index].spec.replicas
|
||||||
deployments_list.append([namespace,deployment])
|
if verbose : print(" "+str(deployment)+" -- Replicas: "+str(replicas))
|
||||||
|
deployments_list.append([namespace,deployment,replicas])
|
||||||
return deployments_list
|
return deployments_list
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
from django.contrib import admin
|
||||||
|
from import_export import resources
|
||||||
|
from django.utils.html import format_html
|
||||||
|
from .models import podcastData
|
||||||
|
from core.admin import UniversalModelAdmin
|
||||||
|
|
||||||
|
# Register your models here.
|
||||||
|
@admin.register(podcastData)
|
||||||
|
class PodcastAdmin(UniversalModelAdmin):
|
||||||
|
list_display = ('podcast_name','clickable_links','enabled')
|
||||||
|
|
||||||
|
link_field = 'podcast_url'
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
from django.apps import AppConfig
|
||||||
|
|
||||||
|
|
||||||
|
class PodcastAggregatorConfig(AppConfig):
|
||||||
|
default_auto_field = 'django.db.models.BigAutoField'
|
||||||
|
name = 'apps.podcast_aggregator'
|
||||||
|
label = 'podcast'
|
||||||
+7
-5
@@ -1,23 +1,25 @@
|
|||||||
# Generated by Django 4.2.30 on 2026-06-19 14:47
|
# Generated by Django 4.2.29 on 2026-06-30 22:05
|
||||||
|
|
||||||
from django.db import migrations, models
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
class Migration(migrations.Migration):
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
initial = True
|
||||||
|
|
||||||
dependencies = [
|
dependencies = [
|
||||||
('cloudmanager', '0001_initial'),
|
|
||||||
]
|
]
|
||||||
|
|
||||||
operations = [
|
operations = [
|
||||||
migrations.CreateModel(
|
migrations.CreateModel(
|
||||||
name='Namespace_Data',
|
name='podcastData',
|
||||||
fields=[
|
fields=[
|
||||||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||||
('namespace', models.CharField(max_length=100)),
|
('podcast_name', models.CharField(max_length=100, null=True)),
|
||||||
|
('podcast_url', models.CharField(max_length=100, null=True)),
|
||||||
],
|
],
|
||||||
options={
|
options={
|
||||||
'db_table': 'namespace',
|
'db_table': 'podcasts',
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
]
|
]
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
# Generated by Django 4.2.29 on 2026-06-30 22:08
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('podcast', '0001_initial'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='podcastdata',
|
||||||
|
name='enabled',
|
||||||
|
field=models.BooleanField(default=True),
|
||||||
|
),
|
||||||
|
]
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
from django.db import models
|
||||||
|
|
||||||
|
class podcastData(models.Model):
|
||||||
|
podcast_name = models.CharField(max_length=100, null=True)
|
||||||
|
podcast_url = models.CharField(max_length=100, null=True)
|
||||||
|
enabled = models.BooleanField(default=True)
|
||||||
|
class Meta:
|
||||||
|
db_table = 'podcasts'
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
from django.test import TestCase
|
||||||
|
|
||||||
|
# Create your tests here.
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
"""
|
||||||
|
URL configuration for django_code project.
|
||||||
|
|
||||||
|
The `urlpatterns` list routes URLs to views. For more information please see:
|
||||||
|
https://docs.djangoproject.com/en/4.2/topics/http/urls/
|
||||||
|
Examples:
|
||||||
|
Function views
|
||||||
|
1. Add an import: from my_app import views
|
||||||
|
2. Add a URL to urlpatterns: path('', views.home, name='home')
|
||||||
|
Class-based views
|
||||||
|
1. Add an import: from other_app.views import Home
|
||||||
|
2. Add a URL to urlpatterns: path('', Home.as_view(), name='home')
|
||||||
|
Including another URLconf
|
||||||
|
1. Import the include() function: from django.urls import include, path
|
||||||
|
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
|
||||||
|
"""
|
||||||
|
from django.urls import path
|
||||||
|
from apps.podcast_aggregator import views as podcast_views
|
||||||
|
|
||||||
|
urlpatterns = [
|
||||||
|
################### cloudmanager ###################
|
||||||
|
path('', podcast_views.execute_podcast),
|
||||||
|
|
||||||
|
]
|
||||||
@@ -0,0 +1,89 @@
|
|||||||
|
import requests
|
||||||
|
import xmltodict
|
||||||
|
from urllib import request as urlrequest
|
||||||
|
import tempfile
|
||||||
|
#Django import
|
||||||
|
from apps.telegram_communication.utils import telegramUtils
|
||||||
|
from .models import podcastData
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
proxy_url = 'http://gluetun-svc.gluetun.svc:8888'
|
||||||
|
proxy = urlrequest.ProxyHandler({
|
||||||
|
'http': proxy_url,
|
||||||
|
'https': proxy_url # Add the handler for HTTPS
|
||||||
|
})
|
||||||
|
|
||||||
|
proxies = {
|
||||||
|
"http" : proxy_url,
|
||||||
|
"https" : proxy_url
|
||||||
|
}
|
||||||
|
|
||||||
|
def rss_to_dict(url):
|
||||||
|
response = requests.get(url)
|
||||||
|
data = xmltodict.parse(response.content)
|
||||||
|
|
||||||
|
print(data['rss'])
|
||||||
|
|
||||||
|
title = data['rss']['channel']['title']
|
||||||
|
|
||||||
|
#Get the keys if needed of debug
|
||||||
|
#print(data['rss'].keys())
|
||||||
|
|
||||||
|
#use first object as it's ordered in a chronological order
|
||||||
|
|
||||||
|
|
||||||
|
today_object = data['rss']['channel']['item']
|
||||||
|
if isinstance(today_object, list):
|
||||||
|
today_object = data['rss']['channel']['item'][0]
|
||||||
|
|
||||||
|
today_title = today_object['title']
|
||||||
|
today_podcast_url = today_object['enclosure']['@url']
|
||||||
|
|
||||||
|
return title,today_title,today_podcast_url
|
||||||
|
|
||||||
|
def download_news_mp3(url_mp3, filename):
|
||||||
|
|
||||||
|
opener = urlrequest.build_opener(proxy)
|
||||||
|
|
||||||
|
urlrequest.install_opener(opener)
|
||||||
|
|
||||||
|
print("Downloading : " + filename +" -- " + url_mp3)
|
||||||
|
try:
|
||||||
|
|
||||||
|
urlrequest.urlretrieve(url_mp3, filename)
|
||||||
|
|
||||||
|
except:
|
||||||
|
print("Can't download " + filename +" -- " + url_mp3 + " == Cancelling")
|
||||||
|
return 0
|
||||||
|
|
||||||
|
def pretty_filename(filename,extension=''):
|
||||||
|
filename = filename.replace(' ', '_')
|
||||||
|
pretty_filename = filename.replace('/', '_')
|
||||||
|
if extension != '':
|
||||||
|
extension = str('.'+extension)
|
||||||
|
return pretty_filename+extension
|
||||||
|
|
||||||
|
def podcasts():
|
||||||
|
telegram = telegramUtils()
|
||||||
|
|
||||||
|
#clear all expired messages before
|
||||||
|
telegram.clear_expired_messages()
|
||||||
|
|
||||||
|
podcasts = podcastData.objects.filter(enabled=True)
|
||||||
|
for podcast in podcasts:
|
||||||
|
url = podcast.podcast_url
|
||||||
|
|
||||||
|
today_podcast = rss_to_dict(url)
|
||||||
|
print(today_podcast)
|
||||||
|
pretty_file_name = pretty_filename(today_podcast[1],'mp3')
|
||||||
|
|
||||||
|
temp = tempfile.TemporaryDirectory()
|
||||||
|
temp_path = temp.name.replace("\\", "/")
|
||||||
|
file_path = temp_path+"/"+pretty_file_name
|
||||||
|
download_news_mp3(today_podcast[2],file_path)
|
||||||
|
print(file_path)
|
||||||
|
telegram.send_document(file_path,str(today_podcast[0])+" "+str(today_podcast[1]))
|
||||||
|
|
||||||
|
#main()
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
from django.http import HttpResponse
|
||||||
|
from .utils import podcasts
|
||||||
|
|
||||||
|
# Create your views here.
|
||||||
|
def execute_podcast(request):
|
||||||
|
podcasts()
|
||||||
|
return HttpResponse('<h1>Generating the podcast!</h1>')
|
||||||
@@ -1,15 +1,26 @@
|
|||||||
from django.contrib import admin,messages
|
from django.contrib import admin,messages
|
||||||
from django.utils.translation import ngettext
|
from django.utils.translation import ngettext
|
||||||
from .models import SimpsonsData,simpsons_data_object
|
from django.utils import timezone
|
||||||
|
from prompt_toolkit.shortcuts import print_container
|
||||||
from import_export import resources
|
from import_export import resources
|
||||||
from import_export.admin import ImportExportModelAdmin
|
from .models import SimpsonsData,urlData
|
||||||
|
from .utils import mark_episode_watched,unwatch_all_episodes,generate_new_urls_for_episode
|
||||||
|
from core.admin import UniversalModelAdmin
|
||||||
|
|
||||||
# Register your models here.
|
# Register your models here.
|
||||||
|
|
||||||
DB = 'simpsons_db'
|
DB = 'simpsons_db'
|
||||||
|
|
||||||
@admin.action(description="Mark episode as seen")
|
@admin.action(description="Mark episode as seen")
|
||||||
def make_seen(modeladmin, request, queryset):
|
def make_seen(modeladmin, request, queryset):
|
||||||
updated = queryset.update(seen="True")
|
updated = queryset.update(seen="True",modified_at=timezone.now())
|
||||||
|
|
||||||
|
for query in queryset.values():
|
||||||
|
print(query)
|
||||||
|
season_number = query.get('season')
|
||||||
|
episode_number = query.get('episode')
|
||||||
|
mark_episode_watched(season_number,episode_number,"watched")
|
||||||
|
|
||||||
modeladmin.message_user(
|
modeladmin.message_user(
|
||||||
request,
|
request,
|
||||||
ngettext(
|
ngettext(
|
||||||
@@ -24,6 +35,12 @@ def make_seen(modeladmin, request, queryset):
|
|||||||
@admin.action(description="Mark episode as not seen")
|
@admin.action(description="Mark episode as not seen")
|
||||||
def make_unseen(modeladmin, request, queryset):
|
def make_unseen(modeladmin, request, queryset):
|
||||||
updated = queryset.update(seen="False")
|
updated = queryset.update(seen="False")
|
||||||
|
for query in queryset.values():
|
||||||
|
print(query)
|
||||||
|
season_number = query.get('season')
|
||||||
|
episode_number = query.get('episode')
|
||||||
|
mark_episode_watched(season_number,episode_number,"unwatched")
|
||||||
|
|
||||||
modeladmin.message_user(
|
modeladmin.message_user(
|
||||||
request,
|
request,
|
||||||
ngettext(
|
ngettext(
|
||||||
@@ -35,16 +52,25 @@ def make_unseen(modeladmin, request, queryset):
|
|||||||
messages.SUCCESS,
|
messages.SUCCESS,
|
||||||
)
|
)
|
||||||
|
|
||||||
@admin.action(description="create_entry")
|
@admin.action(description="mark all of them as unseen on betaserie")
|
||||||
def create_entry(modeladmin, request, queryset):
|
def unseen_betaserie(modeladmin, request, queryset):
|
||||||
simpsons_data_object.create(season=2, episode=3, url="google.com", seen=True)
|
unwatch_all_episodes()
|
||||||
|
|
||||||
|
@admin.action(description="generate new urls for episode")
|
||||||
|
def generate_new_urls(modeladmin, request, queryset):
|
||||||
|
generate_new_urls_for_episode()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@admin.register(SimpsonsData)
|
@admin.register(SimpsonsData)
|
||||||
class EpisodeAdmin(ImportExportModelAdmin):
|
class EpisodeAdmin(UniversalModelAdmin):
|
||||||
list_display = ('season', 'episode', 'url', 'seen')
|
list_display = [field.name for field in SimpsonsData._meta.fields if field.name != 'id']
|
||||||
list_filter = ['seen']
|
list_display += ['clickable_links']
|
||||||
|
list_filter = ['seen','modified_at']
|
||||||
|
#list_filter = ['seen']
|
||||||
fields = ['season', 'episode', 'url', 'seen']
|
fields = ['season', 'episode', 'url', 'seen']
|
||||||
actions = [make_seen,make_unseen,create_entry]
|
actions = [make_seen,make_unseen,unseen_betaserie,generate_new_urls]
|
||||||
|
search_fields = ['season', 'episode', 'url', 'seen']
|
||||||
|
|
||||||
def get_queryset(self, request):
|
def get_queryset(self, request):
|
||||||
return super().get_queryset(request).using(DB)
|
return super().get_queryset(request).using(DB)
|
||||||
@@ -57,3 +83,17 @@ class EpisodeAdmin(ImportExportModelAdmin):
|
|||||||
|
|
||||||
def delete_queryset(self, request, queryset):
|
def delete_queryset(self, request, queryset):
|
||||||
queryset.using(DB).delete()
|
queryset.using(DB).delete()
|
||||||
|
|
||||||
|
@admin.register(urlData)
|
||||||
|
class urldataAdmin(UniversalModelAdmin):
|
||||||
|
list_display = ('url_example', 'prefix', 'infix', 'suffix','addedDate')
|
||||||
|
|
||||||
|
|
||||||
|
fieldsets = [
|
||||||
|
(
|
||||||
|
None,
|
||||||
|
{
|
||||||
|
'fields': (('prefix', 'infix', 'suffix'), 'url_example')
|
||||||
|
},
|
||||||
|
)
|
||||||
|
]
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
# Generated by Django 4.2.30 on 2026-06-16 08:46
|
# Generated by Django 4.2.29 on 2026-06-22 20:21
|
||||||
|
|
||||||
from django.db import migrations, models
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|||||||
@@ -1,41 +0,0 @@
|
|||||||
# Generated by Django 4.2.29 on 2026-06-21 18:21
|
|
||||||
|
|
||||||
from django.db import migrations, models
|
|
||||||
import django.db.models.deletion
|
|
||||||
|
|
||||||
|
|
||||||
class Migration(migrations.Migration):
|
|
||||||
|
|
||||||
dependencies = [
|
|
||||||
('simpsons', '0001_initial'),
|
|
||||||
]
|
|
||||||
|
|
||||||
operations = [
|
|
||||||
migrations.CreateModel(
|
|
||||||
name='Author',
|
|
||||||
fields=[
|
|
||||||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
|
||||||
('name', models.CharField(max_length=100)),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
migrations.CreateModel(
|
|
||||||
name='Category',
|
|
||||||
fields=[
|
|
||||||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
|
||||||
('name', models.CharField(max_length=100)),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
migrations.CreateModel(
|
|
||||||
name='Book',
|
|
||||||
fields=[
|
|
||||||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
|
||||||
('name', models.CharField(max_length=100, verbose_name='Book name')),
|
|
||||||
('author_email', models.EmailField(blank=True, max_length=75, verbose_name='Author email')),
|
|
||||||
('imported', models.BooleanField(default=False)),
|
|
||||||
('published', models.DateField(blank=True, null=True, verbose_name='Published')),
|
|
||||||
('price', models.DecimalField(blank=True, decimal_places=2, max_digits=10, null=True)),
|
|
||||||
('author', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to='simpsons.author')),
|
|
||||||
('categories', models.ManyToManyField(blank=True, to='simpsons.category')),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
]
|
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
# Generated by Django 4.2.29 on 2026-07-05 13:32
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('simpsons', '0001_initial'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='simpsonsdata',
|
||||||
|
name='modified_at',
|
||||||
|
field=models.DateTimeField(auto_now=True),
|
||||||
|
),
|
||||||
|
]
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
# Generated by Django 4.2.29 on 2026-07-05 13:40
|
||||||
|
|
||||||
|
import datetime
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('simpsons', '0002_simpsonsdata_modified_at'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='simpsonsdata',
|
||||||
|
name='modified_at',
|
||||||
|
field=models.DateTimeField(default=datetime.datetime(1970, 1, 1, 0, 0)),
|
||||||
|
),
|
||||||
|
]
|
||||||
-30
@@ -1,30 +0,0 @@
|
|||||||
# Generated by Django 4.2.29 on 2026-06-21 20:11
|
|
||||||
|
|
||||||
from django.db import migrations
|
|
||||||
|
|
||||||
|
|
||||||
class Migration(migrations.Migration):
|
|
||||||
|
|
||||||
dependencies = [
|
|
||||||
('simpsons', '0002_author_category_book'),
|
|
||||||
]
|
|
||||||
|
|
||||||
operations = [
|
|
||||||
migrations.RemoveField(
|
|
||||||
model_name='book',
|
|
||||||
name='author',
|
|
||||||
),
|
|
||||||
migrations.RemoveField(
|
|
||||||
model_name='book',
|
|
||||||
name='categories',
|
|
||||||
),
|
|
||||||
migrations.DeleteModel(
|
|
||||||
name='Author',
|
|
||||||
),
|
|
||||||
migrations.DeleteModel(
|
|
||||||
name='Book',
|
|
||||||
),
|
|
||||||
migrations.DeleteModel(
|
|
||||||
name='Category',
|
|
||||||
),
|
|
||||||
]
|
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
# Generated by Django 4.2.29 on 2026-07-05 13:43
|
||||||
|
|
||||||
|
from django.db import migrations
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('simpsons', '0003_alter_simpsonsdata_modified_at'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.RemoveField(
|
||||||
|
model_name='simpsonsdata',
|
||||||
|
name='modified_at',
|
||||||
|
),
|
||||||
|
]
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
# Generated by Django 4.2.30 on 2026-07-07 08:35
|
||||||
|
|
||||||
|
import datetime
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('simpsons', '0004_remove_simpsonsdata_modified_at'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='simpsonsdata',
|
||||||
|
name='modified_at',
|
||||||
|
field=models.DateTimeField(default=datetime.datetime(1970, 1, 1, 0, 0)),
|
||||||
|
),
|
||||||
|
]
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
# Generated by Django 4.2.30 on 2026-07-07 08:40
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('simpsons', '0005_simpsonsdata_modified_at'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.CreateModel(
|
||||||
|
name='urlData',
|
||||||
|
fields=[
|
||||||
|
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||||
|
('url_example', models.CharField(max_length=1000)),
|
||||||
|
('prefix', models.CharField(max_length=1000)),
|
||||||
|
('infix', models.CharField(max_length=1000)),
|
||||||
|
('suffix', models.CharField(max_length=1000)),
|
||||||
|
('addedDate', models.DateField(auto_now_add=True, null=True, verbose_name='Published')),
|
||||||
|
],
|
||||||
|
options={
|
||||||
|
'db_table': 'redirectUrl',
|
||||||
|
},
|
||||||
|
),
|
||||||
|
]
|
||||||
+28
@@ -0,0 +1,28 @@
|
|||||||
|
# Generated by Django 4.2.30 on 2026-07-07 08:59
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('simpsons', '0006_urldata'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='urldata',
|
||||||
|
name='infix',
|
||||||
|
field=models.CharField(help_text='8&episode=', max_length=1000),
|
||||||
|
),
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='urldata',
|
||||||
|
name='prefix',
|
||||||
|
field=models.CharField(help_text='https://www.1shows.org/tv/456-the-simpsons?streaming=true&season=', max_length=1000),
|
||||||
|
),
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='urldata',
|
||||||
|
name='url_example',
|
||||||
|
field=models.CharField(help_text='https://www.1shows.org/tv/456-the-simpsons?streaming=true&season=18&episode=5', max_length=1000),
|
||||||
|
),
|
||||||
|
]
|
||||||
+34
@@ -0,0 +1,34 @@
|
|||||||
|
# Generated by Django 4.2.30 on 2026-07-07 09:28
|
||||||
|
|
||||||
|
import datetime
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('simpsons', '0007_alter_urldata_infix_alter_urldata_prefix_and_more'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='simpsonsdata',
|
||||||
|
name='modified_at',
|
||||||
|
field=models.DateTimeField(default=datetime.datetime(1970, 1, 1, 0, 0, tzinfo=datetime.timezone.utc)),
|
||||||
|
),
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='urldata',
|
||||||
|
name='infix',
|
||||||
|
field=models.CharField(blank=True, help_text='&episode=', max_length=1000, null=True),
|
||||||
|
),
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='urldata',
|
||||||
|
name='prefix',
|
||||||
|
field=models.CharField(blank=True, help_text='https://www.1shows.org/tv/456-the-simpsons?streaming=true&season=', max_length=1000, null=True),
|
||||||
|
),
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='urldata',
|
||||||
|
name='suffix',
|
||||||
|
field=models.CharField(blank=True, max_length=1000, null=True),
|
||||||
|
),
|
||||||
|
]
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
# Generated by Django 4.2.30 on 2026-09-17 21:26
|
||||||
|
|
||||||
|
import datetime
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('simpsons', '0008_alter_simpsonsdata_modified_at_alter_urldata_infix_and_more'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='simpsonsdata',
|
||||||
|
name='modified_at',
|
||||||
|
field=models.DateTimeField(default=datetime.datetime(1969, 12, 31, 23, 0, tzinfo=datetime.timezone.utc)),
|
||||||
|
),
|
||||||
|
]
|
||||||
@@ -1,12 +1,27 @@
|
|||||||
from django.db import models
|
from django.db import models
|
||||||
|
from datetime import datetime
|
||||||
|
from django.utils.timezone import make_aware
|
||||||
|
|
||||||
|
EPOCH = make_aware(datetime(1970, 1, 1))
|
||||||
|
|
||||||
class SimpsonsData(models.Model):
|
class SimpsonsData(models.Model):
|
||||||
season = models.IntegerField()
|
season = models.IntegerField()
|
||||||
episode = models.IntegerField()
|
episode = models.IntegerField()
|
||||||
url = models.CharField(max_length=1000)
|
url = models.CharField(max_length=1000)
|
||||||
seen = models.BooleanField()
|
seen = models.BooleanField()
|
||||||
|
modified_at = models.DateTimeField(default=EPOCH)
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
db_table = 'episodes'
|
db_table = 'episodes'
|
||||||
|
|
||||||
|
class urlData(models.Model):
|
||||||
|
url_example = models.CharField(max_length=1000, help_text="https://www.1shows.org/tv/456-the-simpsons?streaming=true&season=18&episode=5")
|
||||||
|
prefix = models.CharField(max_length=1000, help_text="https://www.1shows.org/tv/456-the-simpsons?streaming=true&season=",blank=True, null=True)
|
||||||
|
infix = models.CharField(max_length=1000, help_text="&episode=",blank=True, null=True)
|
||||||
|
suffix = models.CharField(max_length=1000, help_text="" ,blank=True, null=True)
|
||||||
|
addedDate = models.DateField('Published', blank=True, null=True, auto_now_add=True)
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
db_table = 'redirectUrl'
|
||||||
|
|
||||||
simpsons_data_object = SimpsonsData.objects.using('simpsons_db')
|
simpsons_data_object = SimpsonsData.objects.using('simpsons_db')
|
||||||
|
|||||||
@@ -0,0 +1,25 @@
|
|||||||
|
"""
|
||||||
|
URL configuration for django_code project.
|
||||||
|
|
||||||
|
The `urlpatterns` list routes URLs to views. For more information please see:
|
||||||
|
https://docs.djangoproject.com/en/4.2/topics/http/urls/
|
||||||
|
Examples:
|
||||||
|
Function views
|
||||||
|
1. Add an import: from my_app import views
|
||||||
|
2. Add a URL to urlpatterns: path('', views.home, name='home')
|
||||||
|
Class-based views
|
||||||
|
1. Add an import: from other_app.views import Home
|
||||||
|
2. Add a URL to urlpatterns: path('', Home.as_view(), name='home')
|
||||||
|
Including another URLconf
|
||||||
|
1. Import the include() function: from django.urls import include, path
|
||||||
|
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
|
||||||
|
"""
|
||||||
|
from django.urls import path
|
||||||
|
from apps.random_simpsons import views as random_simpsons
|
||||||
|
|
||||||
|
urlpatterns = [
|
||||||
|
################### Simpsons ###################
|
||||||
|
path('hello', random_simpsons.hello),
|
||||||
|
path('', random_simpsons.episode_generator),
|
||||||
|
path('download_file/', random_simpsons.download_file),
|
||||||
|
]
|
||||||
@@ -0,0 +1,88 @@
|
|||||||
|
from django.db.models import Count
|
||||||
|
from django.core.exceptions import MultipleObjectsReturned
|
||||||
|
from celery.worker.state import active_requests
|
||||||
|
from requests.compat import str
|
||||||
|
from django.utils import timezone
|
||||||
|
from apps.betaserie.utils import betaserieUtils
|
||||||
|
from .models import simpsons_data_object,urlData
|
||||||
|
|
||||||
|
betaserie = betaserieUtils()
|
||||||
|
|
||||||
|
simpsons_id = 12
|
||||||
|
|
||||||
|
|
||||||
|
def mark_episode_watched(season,episode,action,verbose=False):
|
||||||
|
#mark episode as seen in DB
|
||||||
|
simpsons_data_object.filter(season=season, episode=episode).values('seen').update(seen=True,modified_at=timezone.now())
|
||||||
|
|
||||||
|
|
||||||
|
if verbose : print("season_number: "+str(season))
|
||||||
|
if verbose : print("episode_number: "+str(episode))
|
||||||
|
|
||||||
|
#mark episode as seen in betaserie
|
||||||
|
episode_number = "S"+str(season)+"E"+str(episode)
|
||||||
|
|
||||||
|
episode_id,episode_seen = betaserie.identify_episode(simpsons_id,episode_number)
|
||||||
|
|
||||||
|
if action == "watched":
|
||||||
|
betaserie.mark_episodes_watched(episode_id)
|
||||||
|
elif action == "unwatched":
|
||||||
|
betaserie.unmark_episodes_watched(episode_id)
|
||||||
|
else:
|
||||||
|
print("Parameter action not in range")
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
def unwatch_all_episodes():
|
||||||
|
maximum_number_of_seasons = simpsons_data_object.aggregate(unique_season=Count('season', distinct=True))['unique_season']
|
||||||
|
print("maximum_number_of_seasons: "+str(maximum_number_of_seasons))
|
||||||
|
for season in range(1,maximum_number_of_seasons+1):
|
||||||
|
maximum_number_of_episodes = simpsons_data_object.filter(season=season).count()
|
||||||
|
print("maximum_number_of_episodes for "+str(season)+": "+str(maximum_number_of_episodes))
|
||||||
|
for episode in range(1,maximum_number_of_episodes+1):
|
||||||
|
print("S"+str(season)+"E"+str(episode))
|
||||||
|
mark_episode_watched(season,episode,"unwatched")
|
||||||
|
|
||||||
|
|
||||||
|
def generate_new_urls_for_episode(verbose=False):
|
||||||
|
# kisscartoons didn't work anymore so moving to another website with the format:
|
||||||
|
# URL.com/simpsons/season=XX&episode=XX
|
||||||
|
# example
|
||||||
|
# https://www.1shows.org/tv/456-the-simpsons?streaming=true&season=33&episode=18
|
||||||
|
|
||||||
|
seasons_information,maximum_number_season = betaserie.series_information(simpsons_id)
|
||||||
|
|
||||||
|
|
||||||
|
#for the simpsons, there is a season 0 which increase the count of seasons by 1
|
||||||
|
# we need to remove this entry ,
|
||||||
|
# so we cannot trust the maximum_number_season coming from simpsons_series_information
|
||||||
|
|
||||||
|
# edit 26/08/2026
|
||||||
|
# I updated the function betaserie.series_information to remove this season 0
|
||||||
|
|
||||||
|
for season in range(1,maximum_number_season+1):
|
||||||
|
# the list doesn't start with season 0 anymore so we cannot use the season number as index
|
||||||
|
# we need to add -1
|
||||||
|
|
||||||
|
number_episodes_in_season = int(seasons_information[season-1]['episodes'])
|
||||||
|
|
||||||
|
for episode in range(1,number_episodes_in_season+1):
|
||||||
|
if verbose : print("Season: "+str(season))
|
||||||
|
if verbose : print("episode: "+str(episode))
|
||||||
|
|
||||||
|
new_url_object = urlData.objects.all().order_by('-addedDate').first()
|
||||||
|
new_url = str(new_url_object.prefix)+str(season)+str(new_url_object.infix)+str(episode)+str(new_url_object.suffix)
|
||||||
|
|
||||||
|
if verbose : print(new_url)
|
||||||
|
try:
|
||||||
|
obj,created = simpsons_data_object.get_or_create(
|
||||||
|
season=season,
|
||||||
|
episode=episode,
|
||||||
|
defaults={"url":new_url,"seen":"False"}
|
||||||
|
)
|
||||||
|
obj.url=new_url
|
||||||
|
obj.save()
|
||||||
|
except MultipleObjectsReturned:
|
||||||
|
print("duplicated object for season: "+str(episode)+" episode: "+str(episode)+", ignoring")
|
||||||
|
|
||||||
|
return 0
|
||||||
@@ -1,41 +1,53 @@
|
|||||||
from django.http import HttpResponse
|
from django.http import HttpResponse
|
||||||
from django.db.models import Count
|
from django.db.models import Count
|
||||||
from django.shortcuts import redirect
|
from django.shortcuts import redirect
|
||||||
from apps.random_simpsons.models import SimpsonsData,simpsons_data_object
|
from .models import SimpsonsData,simpsons_data_object
|
||||||
|
from .utils import mark_episode_watched
|
||||||
import random
|
import random
|
||||||
|
import threading
|
||||||
|
|
||||||
def hello(request):
|
def hello(request):
|
||||||
return HttpResponse('<h1>Hello Simpsons view!</h1>')
|
return HttpResponse('<h1>Hello Simpsons view!</h1>')
|
||||||
|
|
||||||
def episode_generator(request):
|
def episode_generator(request):
|
||||||
#simpsons_data_object = SimpsonsData.objects.using('simpsons_db')
|
|
||||||
|
|
||||||
boolean_restart = True;
|
boolean_restart = True;
|
||||||
|
simpsons_object = {}
|
||||||
while (boolean_restart):
|
while (boolean_restart):
|
||||||
maximum_number_of_seasons = simpsons_data_object.aggregate(unique_season=Count('season', distinct=True))['unique_season']
|
maximum_number_of_seasons = simpsons_data_object.aggregate(unique_season=Count('season', distinct=True))['unique_season']
|
||||||
|
|
||||||
random_seasons = random.randint(1, maximum_number_of_seasons)
|
random_season = random.randint(1, maximum_number_of_seasons)
|
||||||
print("random season: " + str(random_seasons))
|
print("random season: " + str(random_season))
|
||||||
|
|
||||||
maximum_number_of_episodes = simpsons_data_object.filter(season=random_seasons).count()
|
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)
|
random_episode = random.randint(1, maximum_number_of_episodes)
|
||||||
print("random episode: " + str(random_episode))
|
print("random episode: " + str(random_episode))
|
||||||
|
|
||||||
|
simpsons_object = simpsons_object.filter(episode=random_episode)
|
||||||
|
|
||||||
episode_seen = simpsons_data_object.filter(season=random_seasons, episode=random_episode).values('seen')[0]['seen']
|
episode_seen = simpsons_object.values('seen')[0]['seen']
|
||||||
|
|
||||||
if not(episode_seen):
|
if not(episode_seen):
|
||||||
boolean_restart = False
|
boolean_restart = False
|
||||||
else:
|
else:
|
||||||
print("episode "+str(random_episode)+" from season "+str(random_seasons)+" already seen")
|
print("episode "+str(random_episode)+" from season "+str(random_season)+" already seen")
|
||||||
|
|
||||||
random_url = simpsons_data_object.filter(season=random_seasons, episode=random_episode).values('url')[0]['url']
|
|
||||||
|
|
||||||
#Set episode as seen
|
#Set episode as seen
|
||||||
# It will still update an already seem episode but it works and I'm lazy
|
# It will still update an already seem episode but it works and I'm lazy
|
||||||
|
|
||||||
simpsons_data_object.filter(season=random_seasons, episode=random_episode).values('seen').update(seen=True)
|
|
||||||
|
#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))
|
return redirect(str(random_url))
|
||||||
|
|
||||||
@@ -60,3 +72,4 @@ def download_mo(request,file):
|
|||||||
file_name = file[5:]
|
file_name = file[5:]
|
||||||
response['Content-Disposition'] = 'inline; filename=' + file_name
|
response['Content-Disposition'] = 'inline; filename=' + file_name
|
||||||
return response
|
return response
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,33 @@
|
|||||||
|
"""
|
||||||
|
URL configuration for django_code project.
|
||||||
|
|
||||||
|
The `urlpatterns` list routes URLs to views. For more information please see:
|
||||||
|
https://docs.djangoproject.com/en/4.2/topics/http/urls/
|
||||||
|
Examples:
|
||||||
|
Function views
|
||||||
|
1. Add an import: from my_app import views
|
||||||
|
2. Add a URL to urlpatterns: path('', views.home, name='home')
|
||||||
|
Class-based views
|
||||||
|
1. Add an import: from other_app.views import Home
|
||||||
|
2. Add a URL to urlpatterns: path('', Home.as_view(), name='home')
|
||||||
|
Including another URLconf
|
||||||
|
1. Import the include() function: from django.urls import include, path
|
||||||
|
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
|
||||||
|
"""
|
||||||
|
from django.urls import path
|
||||||
|
from apps.stash_management import apps as stashapp
|
||||||
|
from apps.stash_management import views as stashview
|
||||||
|
|
||||||
|
urlpatterns = [
|
||||||
|
################## stash #####
|
||||||
|
path('', stashview.home),
|
||||||
|
path('hello/', stashapp.hello),
|
||||||
|
path('form/', stashapp.form),
|
||||||
|
path('incremental/', stashapp.incremental),
|
||||||
|
path('album/', stashapp.album),
|
||||||
|
path('album-form/', stashapp.album_form, name='submit_form'),
|
||||||
|
path('simple/', stashapp.simple),
|
||||||
|
path('simple-form/', stashapp.simple_form, name='submit_form'),
|
||||||
|
path('submit-form/', stashapp.handle_survey_form, name='submit_form'),
|
||||||
|
path('incremental-form/', stashapp.incremental_form, name='submit_form'),
|
||||||
|
]
|
||||||
@@ -0,0 +1,100 @@
|
|||||||
|
from django.contrib import admin
|
||||||
|
from django.utils.html import format_html
|
||||||
|
from .models import StreamingSiteTestingData,StreamingRedirectData
|
||||||
|
from .utils import full_testing
|
||||||
|
from apps.website_redirection.utils import redirect_method
|
||||||
|
from urllib.parse import urlsplit, urlunsplit
|
||||||
|
from core.admin import UniversalModelAdmin
|
||||||
|
|
||||||
|
|
||||||
|
@admin.action(description="Add this show to streaming")
|
||||||
|
def re_redirect(modeladmin, request, queryset):
|
||||||
|
output_generated = ""
|
||||||
|
for query in queryset.values():
|
||||||
|
print(query)
|
||||||
|
key = "streaming"
|
||||||
|
value = query.get('url_display')
|
||||||
|
output_generated = output_generated + redirect_method(key,value)+";"
|
||||||
|
|
||||||
|
modeladmin.message_user(
|
||||||
|
request,
|
||||||
|
output_generated
|
||||||
|
)
|
||||||
|
|
||||||
|
@admin.action(description="check the URLs")
|
||||||
|
def check(modeladmin, request, queryset):
|
||||||
|
for query in queryset:
|
||||||
|
website_url = query.url
|
||||||
|
status=full_testing(website_url)[0]
|
||||||
|
result= full_testing(website_url)[1]
|
||||||
|
print(str(query.url)+": "+str(status)+" -> "+str(result))
|
||||||
|
query.status = status
|
||||||
|
query.result = result
|
||||||
|
query.save(update_fields=["status","result"])
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@admin.action(description="cleaning the url")
|
||||||
|
def urlcleaning(modeladmin, request, queryset):
|
||||||
|
for query in queryset:
|
||||||
|
# Split the URL into components
|
||||||
|
parsed = urlsplit(query.url)
|
||||||
|
|
||||||
|
# Rebuild using only scheme and netloc, adding a trailing slash at the end
|
||||||
|
base_url = urlunsplit((parsed.scheme, parsed.netloc, "/", "", ""))
|
||||||
|
query.url = base_url
|
||||||
|
query.save(update_fields=["url"])
|
||||||
|
print("Cleaning :"+str(base_url))
|
||||||
|
|
||||||
|
return 0
|
||||||
|
@admin.register(StreamingSiteTestingData)
|
||||||
|
class streamingAdmin(UniversalModelAdmin):
|
||||||
|
list_display = ['clickable_links','result_colored','newstatus']
|
||||||
|
fields = ['url']
|
||||||
|
actions = [check,urlcleaning]
|
||||||
|
|
||||||
|
def result_colored(self, obj):
|
||||||
|
colors = {
|
||||||
|
'REACHABLE': 'green',
|
||||||
|
'VPN REQUIRED': 'yellow',
|
||||||
|
'UNREACHABLE': 'red',
|
||||||
|
}
|
||||||
|
|
||||||
|
return format_html(
|
||||||
|
'<b style="background:{};">{}</b>',
|
||||||
|
colors[obj.result],
|
||||||
|
obj.result,
|
||||||
|
)
|
||||||
|
def newstatus(self, obj):
|
||||||
|
if obj.status != '200':
|
||||||
|
return format_html('<div style="width:100%%; height:100%%; background-color:orange;">{}</div>', obj.status)
|
||||||
|
#return obj.status
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@admin.register(StreamingRedirectData)
|
||||||
|
class StreamingRedirectAdmin(UniversalModelAdmin):
|
||||||
|
list_display = ['name','image_tag','season','episode','randomViewing','clickable_links','addedDate','alias']
|
||||||
|
actions = [re_redirect]
|
||||||
|
|
||||||
|
#fields = ['name','season','episode','url_example','prefix','infix','suffix','alias','randomViewing','seasonInformation']
|
||||||
|
fieldsets = (
|
||||||
|
(
|
||||||
|
'Serie', {
|
||||||
|
'fields': ('name', 'season', 'episode','randomViewing')
|
||||||
|
}),
|
||||||
|
(
|
||||||
|
'url', {
|
||||||
|
|
||||||
|
'fields': (('prefix','infix','suffix'))
|
||||||
|
}),
|
||||||
|
(
|
||||||
|
'Information', {
|
||||||
|
"classes": ["collapse"],
|
||||||
|
'fields': ('seasonInformation','alias','betaserieShowId','maximumNumberSeason','poster_url')
|
||||||
|
}),
|
||||||
|
)
|
||||||
|
link_field = 'url_display'
|
||||||
|
|
||||||
|
def image_tag(self,obj):
|
||||||
|
return format_html('<img src="{0}" style="width: 355px; height:200px;" />'.format(obj.poster_url))
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
from django.apps import AppConfig
|
||||||
|
|
||||||
|
|
||||||
|
class StreamingConfig(AppConfig):
|
||||||
|
default_auto_field = 'django.db.models.BigAutoField'
|
||||||
|
name = 'apps.streaming'
|
||||||
|
label = 'streaming'
|
||||||
@@ -0,0 +1,26 @@
|
|||||||
|
# Generated by Django 4.2.30 on 2026-08-05 12:00
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
initial = True
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.CreateModel(
|
||||||
|
name='streamingData',
|
||||||
|
fields=[
|
||||||
|
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||||
|
('url', models.CharField(max_length=1000)),
|
||||||
|
('addedDate', models.DateField(auto_now_add=True, null=True, verbose_name='Published')),
|
||||||
|
('status', models.CharField(blank=True, max_length=1000, null=True)),
|
||||||
|
],
|
||||||
|
options={
|
||||||
|
'db_table': 'streaming',
|
||||||
|
},
|
||||||
|
),
|
||||||
|
]
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
# Generated by Django 4.2.30 on 2026-08-05 13:44
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('streaming', '0001_initial'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='streamingdata',
|
||||||
|
name='result',
|
||||||
|
field=models.CharField(blank=True, max_length=1000, null=True),
|
||||||
|
),
|
||||||
|
]
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
# Generated by Django 4.2.30 on 2026-08-07 13:13
|
||||||
|
|
||||||
|
import apps.streaming.models
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('streaming', '0002_streamingdata_result'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.CreateModel(
|
||||||
|
name='StreamingRedirectData',
|
||||||
|
fields=[
|
||||||
|
('name', models.CharField(help_text='Name of the show', max_length=1000, primary_key=True, serialize=False)),
|
||||||
|
('url_example', models.CharField(help_text='https://www.1shows.org/tv/456-the-simpsons?streaming=true&season=18&episode=5', max_length=1000)),
|
||||||
|
('prefix', models.CharField(blank=True, help_text='https://www.1shows.org/tv/456-the-simpsons?streaming=true&season=', max_length=1000, null=True)),
|
||||||
|
('infix', models.CharField(blank=True, help_text='&episode=', max_length=1000, null=True)),
|
||||||
|
('suffix', models.CharField(blank=True, max_length=1000, null=True)),
|
||||||
|
('addedDate', models.DateField(auto_now_add=True, null=True, verbose_name='Published')),
|
||||||
|
('alias', models.CharField(default=apps.streaming.models.StreamingRedirectData.sanitize, max_length=1000)),
|
||||||
|
],
|
||||||
|
options={
|
||||||
|
'db_table': 'StreamingRedirect',
|
||||||
|
},
|
||||||
|
),
|
||||||
|
]
|
||||||
+28
@@ -0,0 +1,28 @@
|
|||||||
|
# Generated by Django 4.2.30 on 2026-08-07 14:02
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('streaming', '0003_streamingredirectdata'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='streamingredirectdata',
|
||||||
|
name='episode_to_watch',
|
||||||
|
field=models.IntegerField(default=1),
|
||||||
|
),
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='streamingredirectdata',
|
||||||
|
name='season_to_watch',
|
||||||
|
field=models.IntegerField(default=1),
|
||||||
|
),
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='streamingredirectdata',
|
||||||
|
name='alias',
|
||||||
|
field=models.CharField(blank=True, max_length=1000, null=True),
|
||||||
|
),
|
||||||
|
]
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
# Generated by Django 4.2.30 on 2026-08-07 14:49
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('streaming', '0004_streamingredirectdata_episode_to_watch_and_more'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='streamingredirectdata',
|
||||||
|
name='hello',
|
||||||
|
field=models.CharField(blank=True, max_length=1000, null=True),
|
||||||
|
),
|
||||||
|
]
|
||||||
+22
@@ -0,0 +1,22 @@
|
|||||||
|
# Generated by Django 4.2.30 on 2026-08-07 14:55
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('streaming', '0005_streamingredirectdata_hello'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.RemoveField(
|
||||||
|
model_name='streamingredirectdata',
|
||||||
|
name='hello',
|
||||||
|
),
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='streamingredirectdata',
|
||||||
|
name='seasonInformation',
|
||||||
|
field=models.JSONField(blank=True, max_length=1000, null=True),
|
||||||
|
),
|
||||||
|
]
|
||||||
+22
@@ -0,0 +1,22 @@
|
|||||||
|
# Generated by Django 4.2.30 on 2026-08-07 15:22
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('streaming', '0006_remove_streamingredirectdata_hello_and_more'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.RenameModel(
|
||||||
|
old_name='streamingData',
|
||||||
|
new_name='StreamingSiteTestingData',
|
||||||
|
),
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='streamingredirectdata',
|
||||||
|
name='seasonInformation',
|
||||||
|
field=models.JSONField(blank=True, default='', max_length=1000),
|
||||||
|
),
|
||||||
|
]
|
||||||
+23
@@ -0,0 +1,23 @@
|
|||||||
|
# Generated by Django 4.2.30 on 2026-08-07 15:59
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('streaming', '0007_rename_streamingdata_streamingsitetestingdata_and_more'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='streamingredirectdata',
|
||||||
|
name='randomViewing',
|
||||||
|
field=models.BooleanField(default=False),
|
||||||
|
),
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='streamingredirectdata',
|
||||||
|
name='seasonInformation',
|
||||||
|
field=models.JSONField(blank=True, default=dict),
|
||||||
|
),
|
||||||
|
]
|
||||||
+23
@@ -0,0 +1,23 @@
|
|||||||
|
# Generated by Django 4.2.30 on 2026-08-25 14:06
|
||||||
|
|
||||||
|
from django.db import migrations
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('streaming', '0008_streamingredirectdata_randomviewing_and_more'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.RenameField(
|
||||||
|
model_name='streamingredirectdata',
|
||||||
|
old_name='episode_to_watch',
|
||||||
|
new_name='episode',
|
||||||
|
),
|
||||||
|
migrations.RenameField(
|
||||||
|
model_name='streamingredirectdata',
|
||||||
|
old_name='season_to_watch',
|
||||||
|
new_name='season',
|
||||||
|
),
|
||||||
|
]
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
# Generated by Django 4.2.30 on 2026-08-25 14:08
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('streaming', '0009_rename_episode_to_watch_streamingredirectdata_episode_and_more'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='streamingredirectdata',
|
||||||
|
name='episode',
|
||||||
|
field=models.IntegerField(default=0),
|
||||||
|
),
|
||||||
|
]
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
# Generated by Django 4.2.30 on 2026-08-25 15:13
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('streaming', '0010_alter_streamingredirectdata_episode'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='streamingredirectdata',
|
||||||
|
name='betaserieShowId',
|
||||||
|
field=models.IntegerField(default=0),
|
||||||
|
),
|
||||||
|
]
|
||||||
+18
@@ -0,0 +1,18 @@
|
|||||||
|
# Generated by Django 4.2.30 on 2026-08-25 15:14
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('streaming', '0011_streamingredirectdata_betaserieshowid'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='streamingredirectdata',
|
||||||
|
name='betaserieShowId',
|
||||||
|
field=models.IntegerField(blank=True, null=True),
|
||||||
|
),
|
||||||
|
]
|
||||||
+18
@@ -0,0 +1,18 @@
|
|||||||
|
# Generated by Django 4.2.30 on 2026-08-26 11:26
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('streaming', '0012_alter_streamingredirectdata_betaserieshowid'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='streamingredirectdata',
|
||||||
|
name='maximumNumberSeason',
|
||||||
|
field=models.IntegerField(blank=True, null=True),
|
||||||
|
),
|
||||||
|
]
|
||||||
+22
@@ -0,0 +1,22 @@
|
|||||||
|
# Generated by Django 4.2.30 on 2026-09-04 14:29
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('streaming', '0013_streamingredirectdata_maximumnumberseason'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.RemoveField(
|
||||||
|
model_name='streamingredirectdata',
|
||||||
|
name='url_example',
|
||||||
|
),
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='streamingredirectdata',
|
||||||
|
name='url_display',
|
||||||
|
field=models.CharField(blank=True, help_text='https://www.1shows.org/tv/456-the-simpsons?streaming=true&season=18&episode=5', max_length=1000, null=True),
|
||||||
|
),
|
||||||
|
]
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
# Generated by Django 4.2.30 on 2026-09-17 21:26
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('streaming', '0014_remove_streamingredirectdata_url_example_and_more'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='streamingredirectdata',
|
||||||
|
name='poster_url',
|
||||||
|
field=models.CharField(blank=True, help_text='poster URL', max_length=1000, null=True),
|
||||||
|
),
|
||||||
|
]
|
||||||
@@ -0,0 +1,80 @@
|
|||||||
|
from django.db import models
|
||||||
|
from apps.betaserie.utils import betaserieUtils
|
||||||
|
|
||||||
|
from django_code.core.settings import ENVIRONMENT
|
||||||
|
|
||||||
|
|
||||||
|
# Create your models here.
|
||||||
|
class StreamingSiteTestingData(models.Model):
|
||||||
|
url = models.CharField(max_length=1000)
|
||||||
|
addedDate = models.DateField('Published', blank=True, null=True, auto_now_add=True)
|
||||||
|
status = models.CharField(max_length=1000, blank=True, null=True)
|
||||||
|
result = models.CharField(max_length=1000, blank=True, null=True)
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
db_table = 'streaming'
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
class StreamingRedirectData(models.Model):
|
||||||
|
name = models.CharField(primary_key=True,max_length=1000, help_text="Name of the show")
|
||||||
|
season = models.IntegerField(null=False,default=1)
|
||||||
|
episode = models.IntegerField(null=False,default=0)
|
||||||
|
url_display = models.CharField(max_length=1000, help_text="https://streaming.geeraert.eu/office",blank=True, null=True)
|
||||||
|
prefix = models.CharField(max_length=1000, help_text="https://www.1shows.org/tv/456-the-simpsons?streaming=true&season=",blank=True, null=True)
|
||||||
|
infix = models.CharField(max_length=1000, help_text="&episode=",blank=True, null=True)
|
||||||
|
suffix = models.CharField(max_length=1000, help_text="" ,blank=True, null=True)
|
||||||
|
addedDate = models.DateField('Published', blank=True, null=True, auto_now_add=True)
|
||||||
|
alias = models.CharField(max_length=1000, null=True,blank=True)
|
||||||
|
seasonInformation = models.JSONField(default=dict, blank=True)
|
||||||
|
betaserieShowId = models.IntegerField(null=True,blank=True)
|
||||||
|
maximumNumberSeason = models.IntegerField(null=True,blank=True)
|
||||||
|
randomViewing = models.BooleanField(default=False)
|
||||||
|
poster_url = models.CharField(max_length=1000, help_text="poster URL",blank=True, null=True)
|
||||||
|
|
||||||
|
def sanitize(self, name):
|
||||||
|
return name.replace(" ", "").lower()
|
||||||
|
|
||||||
|
def season_information(self, serie_name):
|
||||||
|
betaserie = betaserieUtils()
|
||||||
|
return betaserie.series_information(betaserie.identify_serie(serie_name))[0]
|
||||||
|
|
||||||
|
def maximum_Number_Season(self, serie_name):
|
||||||
|
betaserie = betaserieUtils()
|
||||||
|
return betaserie.series_information(betaserie.identify_serie(serie_name))[1]
|
||||||
|
|
||||||
|
def betaserie_show_id(self,serie_name):
|
||||||
|
betaserie = betaserieUtils()
|
||||||
|
return betaserie.identify_serie(serie_name)
|
||||||
|
|
||||||
|
def betaserie_poster_url(self,serie_name):
|
||||||
|
betaserie = betaserieUtils()
|
||||||
|
return betaserie.poster_serie(serie_name)
|
||||||
|
|
||||||
|
def url_display_set(self,alias):
|
||||||
|
if ENVIRONMENT == "PRODUCTION":
|
||||||
|
url = "https://streaming.geeraert.eu/"
|
||||||
|
else:
|
||||||
|
url = "https://streaming-testing.geeraert.eu/"
|
||||||
|
|
||||||
|
return url+alias
|
||||||
|
|
||||||
|
|
||||||
|
def save(self, *args, **kwargs):
|
||||||
|
if not self.seasonInformation :
|
||||||
|
self.seasonInformation = self.season_information(self.name)
|
||||||
|
if not self.alias:
|
||||||
|
self.alias = self.sanitize(self.name)
|
||||||
|
if not self.betaserieShowId:
|
||||||
|
self.betaserieShowId = self.betaserie_show_id(self.name)
|
||||||
|
if not self.maximumNumberSeason:
|
||||||
|
self.maximumNumberSeason = self.maximum_Number_Season(self.name)
|
||||||
|
if not self.url_display:
|
||||||
|
self.url_display = self.url_display_set(self.alias)
|
||||||
|
if not self.poster_url:
|
||||||
|
self.poster_url = self.betaserie_poster_url(self.name)
|
||||||
|
super().save(*args, **kwargs)
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
db_table = 'StreamingRedirect'
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
from django.test import TestCase
|
||||||
|
|
||||||
|
# Create your tests here.
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
"""
|
||||||
|
URL configuration for django_code project.
|
||||||
|
|
||||||
|
The `urlpatterns` list routes URLs to views. For more information please see:
|
||||||
|
https://docs.djangoproject.com/en/4.2/topics/http/urls/
|
||||||
|
Examples:
|
||||||
|
Function views
|
||||||
|
1. Add an import: from my_app import views
|
||||||
|
2. Add a URL to urlpatterns: path('', views.home, name='home')
|
||||||
|
Class-based views
|
||||||
|
1. Add an import: from other_app.views import Home
|
||||||
|
2. Add a URL to urlpatterns: path('', Home.as_view(), name='home')
|
||||||
|
Including another URLconf
|
||||||
|
1. Import the include() function: from django.urls import include, path
|
||||||
|
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
|
||||||
|
"""
|
||||||
|
|
||||||
|
from django.urls import path
|
||||||
|
from apps.streaming import views as streaming_views
|
||||||
|
|
||||||
|
urlpatterns = [
|
||||||
|
################### streaming ###################
|
||||||
|
path('<str:alias>', streaming_views.streamingRedirect),
|
||||||
|
]
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user