mirror of
https://github.com/NohamR/PronoteBot.git
synced 2025-05-24 00:49:00 +00:00
fix
This commit is contained in:
parent
97a246b1f4
commit
1d4e05e7af
59
getgrades.py
59
getgrades.py
@ -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:
|
if send == 1:
|
||||||
changes+=1
|
if len(new_grades_list) != len(prev_grades):
|
||||||
if changes == 1:
|
changes = 0
|
||||||
content = f"""**{i['subject_name']}** : {i['comment']}
|
while len(new_grades_list) != len(prev_grades):
|
||||||
{datetime.strptime(str(i['date']), "%Y-%m-%d").strftime("%d %B %Y")}
|
prev_grades.append('tmp')
|
||||||
**{i['grade']}/{i['out_of']}** | Coef : {i['coefficient']}
|
for i,old in zip(new_grades_list, prev_grades):
|
||||||
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 i != old:
|
||||||
"""
|
changes+=1
|
||||||
print('content: ', content)
|
if changes == 1:
|
||||||
else:
|
content = f"""**{i['subject_name']}** : {i['comment']}
|
||||||
print(f'{datetime.now().strftime("%H:%M")} : No change')
|
{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)
|
Loading…
x
Reference in New Issue
Block a user