mirror of
https://github.com/NohamR/PronoteBot.git
synced 2025-05-24 00:49:00 +00:00
update (fix crash)
This commit is contained in:
parent
578c56d867
commit
3ca9f33989
BIN
Capture d’écran 2023-12-13 à 19.02.26.png
Normal file
BIN
Capture d’écran 2023-12-13 à 19.02.26.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.2 MiB |
@ -1,14 +1,9 @@
|
|||||||
FROM python:3.10-alpine
|
FROM python:3.10-alpine
|
||||||
|
|
||||||
# Copiez les fichiers nécessaires dans le conteneur
|
|
||||||
COPY getgrades.py .
|
COPY getgrades.py .
|
||||||
# COPY average.txt .
|
|
||||||
# COPY grades.txt .
|
|
||||||
COPY requirements.txt .
|
COPY requirements.txt .
|
||||||
COPY .env .
|
COPY .env .
|
||||||
|
|
||||||
# Installez les dépendances
|
|
||||||
RUN pip install --no-cache-dir -r requirements.txt
|
RUN pip install --no-cache-dir -r requirements.txt
|
||||||
|
|
||||||
# Commande pour exécuter votre programme Python
|
|
||||||
CMD ["python", "-u", "getgrades.py"]
|
CMD ["python", "-u", "getgrades.py"]
|
54
docker-compose.yaml
Normal file
54
docker-compose.yaml
Normal file
@ -0,0 +1,54 @@
|
|||||||
|
name: pronoteapi
|
||||||
|
services:
|
||||||
|
app:
|
||||||
|
cpu_shares: 90
|
||||||
|
command: []
|
||||||
|
deploy:
|
||||||
|
resources:
|
||||||
|
limits:
|
||||||
|
memory: 7943M
|
||||||
|
image: pronoteapi:latest
|
||||||
|
labels:
|
||||||
|
icon: https://camo.githubusercontent.com/3ae516af10d2a609989fece36dda63f4d10ee30cca1dd46564454c5bb07697c9/68747470733a2f2f70726f6e6f746570792e72656164746865646f63732e696f2f656e2f6c61746573742f5f696d616765732f69636f6e2e706e67
|
||||||
|
restart: unless-stopped
|
||||||
|
x-casaos:
|
||||||
|
envs:
|
||||||
|
- container: LOG_LEVEL
|
||||||
|
description:
|
||||||
|
en_us: Log level
|
||||||
|
- container: TZ
|
||||||
|
description:
|
||||||
|
en_us: Timezone
|
||||||
|
volumes:
|
||||||
|
- container: /app/config
|
||||||
|
description:
|
||||||
|
en_us: "Container Path: /app/config"
|
||||||
|
ports: []
|
||||||
|
volumes: []
|
||||||
|
devices: []
|
||||||
|
cap_add: []
|
||||||
|
environment: []
|
||||||
|
network_mode: bridge
|
||||||
|
privileged: false
|
||||||
|
container_name: ""
|
||||||
|
x-casaos:
|
||||||
|
architectures:
|
||||||
|
- amd64
|
||||||
|
- arm64
|
||||||
|
author: nohamr
|
||||||
|
category: Api
|
||||||
|
description:
|
||||||
|
en_us: Recup tes notes sur pronote et les envoie sur un webhooks
|
||||||
|
developer: nohamr
|
||||||
|
hostname: 0910626l.index-education.net/pronote/eleve.html?identifiant=rb5yNZw4HrWKHrcK
|
||||||
|
icon: https://camo.githubusercontent.com/3ae516af10d2a609989fece36dda63f4d10ee30cca1dd46564454c5bb07697c9/68747470733a2f2f70726f6e6f746570792e72656164746865646f63732e696f2f656e2f6c61746573742f5f696d616765732f69636f6e2e706e67
|
||||||
|
index: /
|
||||||
|
main: app
|
||||||
|
port_map: ""
|
||||||
|
scheme: https
|
||||||
|
store_app_id: pronoteapi
|
||||||
|
tagline:
|
||||||
|
en_us: Recup tes notes sur pronote et les envoie sur un webhooks
|
||||||
|
title:
|
||||||
|
custom: ""
|
||||||
|
en_us: PronoteApi
|
158
getgrades.py
158
getgrades.py
@ -2,7 +2,6 @@ import pronotepy
|
|||||||
from pronotepy.ent import ile_de_france
|
from pronotepy.ent import ile_de_france
|
||||||
from datetime import date
|
from datetime import date
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
import schedule
|
|
||||||
import time
|
import time
|
||||||
import json
|
import json
|
||||||
import requests
|
import requests
|
||||||
@ -31,77 +30,82 @@ def envoyer_message_webhook(contenu):
|
|||||||
print(f"Échec de l'envoi du message. Code d'état : {response.status_code}")
|
print(f"Échec de l'envoi du message. Code d'état : {response.status_code}")
|
||||||
|
|
||||||
def refresh(send):
|
def refresh(send):
|
||||||
client = pronotepy.Client('https://0910626l.index-education.net/pronote/eleve.html',
|
try :
|
||||||
username=ENT_USERNAME,
|
client = pronotepy.Client('https://0910626l.index-education.net/pronote/eleve.html',
|
||||||
password=ENT_PASSWORD,
|
username=ENT_USERNAME,
|
||||||
ent=ile_de_france)
|
password=ENT_PASSWORD,
|
||||||
if not client.logged_in:
|
ent=ile_de_france)
|
||||||
exit(1)
|
if not client.logged_in:
|
||||||
|
exit(1)
|
||||||
|
|
||||||
if send == 1:
|
if send == 1:
|
||||||
with open(path + 'grades.txt', 'r') as file:
|
with open(path + 'grades.txt', 'r') as file:
|
||||||
prev_grades = json.load(file)
|
prev_grades = json.load(file)
|
||||||
|
|
||||||
with open(path + 'average.txt', 'r') as file:
|
with open(path + 'average.txt', 'r') as file:
|
||||||
prev_average = json.load(file)
|
prev_average = json.load(file)
|
||||||
|
|
||||||
new_average = client.periods[0].overall_average
|
new_average = client.periods[0].overall_average
|
||||||
|
|
||||||
new_grades_list = []
|
new_grades_list = []
|
||||||
for period in client.periods:
|
for period in client.periods:
|
||||||
for grade in period.grades:
|
for grade in period.grades:
|
||||||
obj = grade.date
|
obj = grade.date
|
||||||
gooddate = obj.isoformat()
|
gooddate = obj.isoformat()
|
||||||
grade_dict = {
|
grade_dict = {
|
||||||
'grade': grade.grade,
|
'grade': grade.grade,
|
||||||
'average': grade.average,
|
'average': grade.average,
|
||||||
'coefficient': grade.coefficient,
|
'coefficient': grade.coefficient,
|
||||||
'comment': grade.comment,
|
'comment': grade.comment,
|
||||||
'date': gooddate,
|
'date': gooddate,
|
||||||
'default_out_of': grade.default_out_of,
|
'default_out_of': grade.default_out_of,
|
||||||
# 'id': grade.id,
|
# 'id': grade.id,
|
||||||
'is_bonus': grade.is_bonus,
|
'is_bonus': grade.is_bonus,
|
||||||
'is_optional': grade.is_optionnal,
|
'is_optional': grade.is_optionnal,
|
||||||
'is_out_of_20': grade.is_out_of_20,
|
'is_out_of_20': grade.is_out_of_20,
|
||||||
'max': grade.max,
|
'max': grade.max,
|
||||||
'min': grade.min,
|
'min': grade.min,
|
||||||
'out_of': grade.out_of,
|
'out_of': grade.out_of,
|
||||||
# 'period_id': grade.period.id,
|
# 'period_id': grade.period.id,
|
||||||
'period_name': grade.period.name,
|
'period_name': grade.period.name,
|
||||||
# 'subject_id': grade.subject.id,
|
# 'subject_id': grade.subject.id,
|
||||||
'subject_groups': grade.subject.groups,
|
'subject_groups': grade.subject.groups,
|
||||||
'subject_name': grade.subject.name,
|
'subject_name': grade.subject.name,
|
||||||
}
|
}
|
||||||
new_grades_list.append(grade_dict)
|
new_grades_list.append(grade_dict)
|
||||||
if send == 1:
|
if send == 1:
|
||||||
if len(new_grades_list) != len(prev_grades):
|
if len(new_grades_list) != len(prev_grades):
|
||||||
changes = 0
|
changes = 0
|
||||||
while len(new_grades_list) != len(prev_grades):
|
while len(new_grades_list) != len(prev_grades):
|
||||||
prev_grades.append('tmp')
|
prev_grades.append('tmp')
|
||||||
for i,old in zip(new_grades_list, prev_grades):
|
for i,old in zip(new_grades_list, prev_grades):
|
||||||
|
|
||||||
if i != old:
|
if i != old:
|
||||||
changes+=1
|
changes+=1
|
||||||
if changes == 1:
|
if changes == 1:
|
||||||
content = f"""**{i['subject_name']}** : {i['comment']}
|
content = f"""**{i['subject_name']}** : {i['comment']}
|
||||||
{datetime.strptime(str(i['date']), "%Y-%m-%d").strftime("%d %B %Y")}
|
{datetime.strptime(str(i['date']), "%Y-%m-%d").strftime("%d %B %Y")}
|
||||||
**{i['grade']}/{i['out_of']}** | Coef : {i['coefficient']}
|
**{i['grade']}/{i['out_of']}** | Coef : {i['coefficient']}
|
||||||
Moy : **{i['average']}/{i['out_of']}**
|
Moy : **{i['average']}/{i['out_of']}**
|
||||||
:arrow_up_small: : {i['max']}/{i['out_of']} | :arrow_down_small: : {i['min']}/{i['out_of']}
|
:arrow_up_small: : {i['max']}/{i['out_of']} | :arrow_down_small: : {i['min']}/{i['out_of']}
|
||||||
|
|
||||||
Moy G : {new_average}({float(new_average)-float(prev_average)})
|
Moy G : {new_average}({float(new_average)-float(prev_average)})
|
||||||
"""
|
"""
|
||||||
print('content: ', content)
|
print('content: ', content)
|
||||||
envoyer_message_webhook(content)
|
envoyer_message_webhook(content)
|
||||||
else:
|
else:
|
||||||
print(f'{datetime.now().strftime("%H:%M")} : No change')
|
print(f'{datetime.now().strftime("%H:%M")} : No change')
|
||||||
|
|
||||||
################
|
################
|
||||||
with open(path + 'grades.txt', 'w') as file:
|
with open(path + 'grades.txt', 'w') as file:
|
||||||
json.dump(new_grades_list, file, indent=2, default=date_encoder)
|
json.dump(new_grades_list, file, indent=2, default=date_encoder)
|
||||||
|
|
||||||
with open(path + 'average.txt', 'w') as file:
|
with open(path + 'average.txt', 'w') as file:
|
||||||
json.dump(new_average, file, indent=2)
|
json.dump(new_average, file, indent=2)
|
||||||
|
|
||||||
|
return 1
|
||||||
|
except Exception as e:
|
||||||
|
return e
|
||||||
|
|
||||||
|
|
||||||
# schedule.every(20).minutes.do(refresh)
|
# schedule.every(20).minutes.do(refresh)
|
||||||
@ -111,19 +115,25 @@ def refresh(send):
|
|||||||
# time.sleep(1)
|
# time.sleep(1)
|
||||||
|
|
||||||
|
|
||||||
try:
|
status = 0
|
||||||
refresh(send = 0)
|
while status != 1:
|
||||||
except Exception as e:
|
status = refresh(send = 0)
|
||||||
print(e)
|
if status != 1 :
|
||||||
refresh(send = 0)
|
print(status)
|
||||||
|
envoyer_message_webhook(status)
|
||||||
|
time.sleep(2*60)
|
||||||
|
|
||||||
min = 20
|
min = 20
|
||||||
print('refresh rate: ', 20)
|
print('refresh rate: ', 20)
|
||||||
while True:
|
while True:
|
||||||
try:
|
status = 0
|
||||||
refresh(send = 1)
|
while status != 1:
|
||||||
except Exception as e:
|
status = refresh(send = 1)
|
||||||
print(e)
|
if status != 1 :
|
||||||
refresh(send = 1)
|
print(status)
|
||||||
|
envoyer_message_webhook(status)
|
||||||
|
time.sleep(2*60)
|
||||||
|
|
||||||
time.sleep(min*60)
|
time.sleep(min*60)
|
||||||
|
|
||||||
### debug
|
### debug
|
||||||
|
50
test.py
50
test.py
@ -1,50 +0,0 @@
|
|||||||
import pronotepy
|
|
||||||
from pronotepy.ent import ile_de_france
|
|
||||||
from datetime import date
|
|
||||||
from datetime import datetime
|
|
||||||
import schedule
|
|
||||||
import time
|
|
||||||
import json
|
|
||||||
import requests
|
|
||||||
import os
|
|
||||||
from dotenv import load_dotenv
|
|
||||||
load_dotenv()
|
|
||||||
DISCORD_WEBHOOKS_PRONOTE = os.getenv("DISCORD_WEBHOOKS_PRONOTE")
|
|
||||||
ENT_USERNAME = os.getenv("ENT_USERNAME")
|
|
||||||
ENT_PASSWORD = os.getenv("ENT_PASSWORD")
|
|
||||||
|
|
||||||
client = pronotepy.Client('https://0910626l.index-education.net/pronote/eleve.html',
|
|
||||||
username=ENT_USERNAME,
|
|
||||||
password=ENT_PASSWORD,
|
|
||||||
ent=ile_de_france)
|
|
||||||
if not client.logged_in:
|
|
||||||
exit(1)
|
|
||||||
|
|
||||||
new_average = client.periods[0].overall_average
|
|
||||||
|
|
||||||
new_grades_list = []
|
|
||||||
for period in client.periods:
|
|
||||||
for grade in period.grades:
|
|
||||||
grade_dict = {
|
|
||||||
'grade': grade.grade,
|
|
||||||
'average': grade.average,
|
|
||||||
'coefficient': grade.coefficient,
|
|
||||||
'comment': grade.comment,
|
|
||||||
'date': grade.date,
|
|
||||||
'default_out_of': grade.default_out_of,
|
|
||||||
'id': grade.id,
|
|
||||||
'is_bonus': grade.is_bonus,
|
|
||||||
'is_optional': grade.is_optionnal,
|
|
||||||
'is_out_of_20': grade.is_out_of_20,
|
|
||||||
'max': grade.max,
|
|
||||||
'min': grade.min,
|
|
||||||
'out_of': grade.out_of,
|
|
||||||
'period_id': grade.period.id,
|
|
||||||
'period_name': grade.period.name,
|
|
||||||
'subject_id': grade.subject.id,
|
|
||||||
'subject_groups': grade.subject.groups,
|
|
||||||
'subject_name': grade.subject.name,
|
|
||||||
}
|
|
||||||
new_grades_list.append(grade_dict)
|
|
||||||
|
|
||||||
print(new_grades_list)
|
|
Loading…
x
Reference in New Issue
Block a user