Skip to content

Commit e5f41b2

Browse files
authored
Merge pull request #2 from Oneloutre/dev_with_logs_notif
Dev with logs notif
2 parents 8b0d72c + 589282e commit e5f41b2

File tree

4 files changed

+58
-5
lines changed

4 files changed

+58
-5
lines changed

main.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,22 +10,26 @@
1010

1111

1212
cookies_file = 'files/session_cookies.pkl'
13+
webhook = webhook_handler.webhook_check()
14+
log_webhook = webhook_handler.log_webhook_check()
1315

1416

1517
def main():
1618

1719
username, password = connection.creds_check()
1820
response, session = connection.connection(username, password)
19-
webhook = webhook_handler.webhook_check()
21+
22+
2023

2124
if 'Ma carte d\'étudiant' in response.text:
2225
print('Connexion réussie!')
23-
#webhook_handler.webhook_send(webhook, 'Connexion réussie!')
26+
if os.path.exists('files/log_webhook.txt'):
27+
webhook_handler.simple_send(log_webhook, 'Connexion réussie!')
2428
json_parser.parser(session, webhook)
2529
with open(cookies_file, 'wb') as f:
2630
pickle.dump(session.cookies, f)
2731
scheduler = schedule.Scheduler()
28-
scheduler.every(15).minutes.do(functools.partial(update_checker.comparer_devoirs_json, session))
32+
scheduler.every(15).minutes.do(functools.partial(update_checker.comparer_devoirs_json, session, log_webhook))
2933

3034
while True:
3135
scheduler.run_pending()
@@ -36,6 +40,8 @@ def main():
3640
main()
3741
else:
3842
print('Erreur: Connexion échouée!')
43+
if os.path.exists('files/log_webhook.txt'):
44+
webhook_handler.simple_send(log_webhook, 'Erreur: Connexion échouée!')
3945
os.remove("files/creds.txt")
4046
os.remove("files/webhook.txt")
4147
main()
@@ -47,5 +53,6 @@ def main():
4753
main()
4854
except Exception as e:
4955
print('Erreur: ' + str(e))
50-
56+
if os.path.exists('files/log_webhook.txt'):
57+
webhook_handler.simple_send(log_webhook, 'Erreur: ' + str(e))
5158
main()

misc/update_checker.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import os
99

1010

11-
def comparer_devoirs_json(session):
11+
def comparer_devoirs_json(session, log_webhook):
1212
try:
1313
if not os.path.exists('files/devoirs.json'):
1414
with open('files/devoirs.json', 'w') as f:
@@ -18,6 +18,8 @@ def comparer_devoirs_json(session):
1818
devoirs = scraper.recuperer_cahier_texte(session)
1919
if devoirs == devoirs_json:
2020
print('Pas de nouveaux devoirs | ' + datetime.now().strftime('%Y-%m-%d %H:%M:%S'))
21+
if os.path.exists('files/log_webhook.txt'):
22+
webhook_handler.simple_send(log_webhook, 'Pas de nouveaux devoirs | ' + datetime.now().strftime('%Y-%m-%d %H:%M:%S'))
2123
else:
2224
diff_elements = [item for item in devoirs if item not in devoirs_json]
2325
for i in diff_elements:

misc/webhook_handler.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,17 @@ def webhook_check():
1717
exit(1)
1818

1919

20+
def log_webhook_check():
21+
try:
22+
if os.path.exists('files/log_webhook.txt'):
23+
with open('files/log_webhook.txt', 'r') as f:
24+
webhook = f.readline().strip()
25+
return webhook
26+
except Exception as e:
27+
print('Erreur: ' + str(e))
28+
exit(1)
29+
30+
2031
def webhook_send(webhook, url_cours, title, color, start, end, description, prof):
2132
url = webhook
2233
data = {
@@ -51,3 +62,31 @@ def webhook_send(webhook, url_cours, title, color, start, end, description, prof
5162
print(err)
5263
else:
5364
print("Payload delivered successfully, code {}.".format(result.status_code))
65+
66+
67+
def simple_send(log_webhook, message):
68+
url = log_webhook
69+
data = {
70+
"embeds": [
71+
{
72+
"type": "rich",
73+
"description": message,
74+
"color": 0x000000,
75+
"thumbnail": {
76+
"url": "https://storage.letudiant.fr/osp/cards/276/mjm-graphic-design-231102102947.jpg",
77+
"height": 0,
78+
"width": 0,
79+
},
80+
"author": {
81+
"name": "MJM",
82+
"url": "https://mjmcloud.com",
83+
"icon_url": "https://cdn-icons-png.flaticon.com/512/462/462642.png"
84+
},
85+
"footer": {
86+
"text": "webhook de log",
87+
"icon_url": "https://cdn.onelots.fr/u/VakI1n.png"
88+
},
89+
}]
90+
}
91+
92+
requests.post(url, json=data)

readme.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,3 +67,8 @@ Si vous souhaitez contribuer au projet, vous pouvez ouvrir une issue ou une pull
6767
## Licence :scroll: :
6868

6969
[License MIT](https://choosealicense.com/licenses/mit/)
70+
71+
72+
## Nouveautés :loudspeaker: :
73+
74+
- ajout d'un fichier log_webhook.txt (facultatif, à ajouter soi-même) pour garder un oeil sur le conteneur docker (à paramétrer manuellement mais comme le webhook.txt)

0 commit comments

Comments
 (0)