This commit is contained in:
√(noham)² 2023-12-21 10:58:44 +01:00
parent 97a246b1f4
commit 1d4e05e7af

View File

@ -24,11 +24,14 @@ def envoyer_message_webhook(contenu):
data = { data = {
'content': contenu 'content': contenu
} }
response = requests.post(DISCORD_WEBHOOKS_PRONOTE, json=data) try:
if response.status_code == 204: response = requests.post(DISCORD_WEBHOOKS_PRONOTE, json=data)
print(f'{datetime.now().strftime("%H:%M")} : Send') if response.status_code == 204:
else: print(f'{datetime.now().strftime("%H:%M")} : Send')
print(f"Échec de l'envoi du message. Code d'état : {response.status_code}") else:
print(f"Échec de l'envoi du message. Code d'état : {response.status_code}")
except Exception as e:
print(e)
def refresh(send): def refresh(send):
content = '' content = ''
@ -75,26 +78,28 @@ def refresh(send):
'subject_name': grade.subject.name, 'subject_name': grade.subject.name,
} }
new_grades_list.append(grade_dict) new_grades_list.append(grade_dict)
if len(new_grades_list) != len(prev_grades):
changes = 0
while len(new_grades_list) != len(prev_grades):
prev_grades.append('tmp')
for i,old in zip(new_grades_list, prev_grades):
if i != old:
changes+=1
if changes == 1:
content = f"""**{i['subject_name']}** : {i['comment']}
{datetime.strptime(str(i['date']), "%Y-%m-%d").strftime("%d %B %Y")}
**{i['grade']}/{i['out_of']}** | Coef : {i['coefficient']}
Moy : **{i['average']}/{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)}) if send == 1:
""" if len(new_grades_list) != len(prev_grades):
print('content: ', content) changes = 0
else: while len(new_grades_list) != len(prev_grades):
print(f'{datetime.now().strftime("%H:%M")} : No change') prev_grades.append('tmp')
for i,old in zip(new_grades_list, prev_grades):
if i != old:
changes+=1
if changes == 1:
content = f"""**{i['subject_name']}** : {i['comment']}
{datetime.strptime(str(i['date']), "%Y-%m-%d").strftime("%d %B %Y")}
**{i['grade']}/{i['out_of']}** | Coef : {i['coefficient']}
Moy : **{i['average']}/{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)})
"""
print('content: ', content)
else:
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:
@ -118,11 +123,14 @@ def refresh(send):
status = 0 status = 0
while status != 1: while status != 1:
status, content = refresh(send = 0) status, content = refresh(send = 0)
print('content: ', content)
print('status: ', status)
if status != 1 : if status != 1 :
print(status) print(status)
envoyer_message_webhook(status) envoyer_message_webhook(status)
time.sleep(2*60) time.sleep(2*60)
min = 20 min = 20
print('refresh rate: ', 20) print('refresh rate: ', 20)
while True: while True:
@ -135,8 +143,7 @@ while True:
time.sleep(2*60) time.sleep(2*60)
elif content != '': elif content != '':
envoyer_message_webhook(content) envoyer_message_webhook(content)
time.sleep(min*60) time.sleep(min*60)
### debug # ### debug
# refresh(send=1) # # refresh(send=1)