-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathEcoleDirect.py
More file actions
103 lines (78 loc) · 4.3 KB
/
Copy pathEcoleDirect.py
File metadata and controls
103 lines (78 loc) · 4.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
import requests
import json
import datetime
class EcoleDirect:
""" Permet de se connecter et faire des requetes a l'API d'école direct
Allow to connect and make requests to Ecoledirect's API """
def __init__(self, username = None, password = None):
"""Create a new EcoleDirect object"""
self.token = None
self.id = None
if username is not None and password is not None:
self.connect(username, password)
def __req(self, url, payload):
"""this function make all requests to the api"""
return requests.post(url, data = payload)
def connect(self, username : str, password : str):
"""create an connection to the API"""
connection = self.__req('https://api.ecoledirecte.com/v3/login.awp', """data={}"identifiant": "{}","motdepasse": "{}"{}""".format("{",username, password, "}"))
if connection.json()['code'] != 200:
print("error ! bad username or password")
else:
self.token = connection.json()['token']
self.id = connection.json()['data']['accounts'][0]['id']
def getWT(self, startDate = datetime.date.today().strftime("%Y-%m-%d"), endDate = (datetime.date.today() + datetime.timedelta(days=6) ).strftime("%Y-%m-%d")):
"""get the work time from the api"""
if self.token is None or self.id is None:
print("Error connection must be acitvate")
return
connection = self.__req('https://api.ecoledirecte.com/v3/E/{}/emploidutemps.awp?verbe=get&'.format(self.id), """data={}"token":"{}","dateDebut": "{}","dateFin": "{}","avecTrous": false,{}""".format("{", self.token,startDate,endDate, "}"))
if connection.json()['code'] != 200:
print("error ! bad username or password")
else:
# self.token = connection.json()['token']
return connection.json()['data']
def getHW(self):
"""get homework from the api"""
if self.token is None or self.id is None:
print("Error connection must be acitvate")
return
connection = self.__req('https://api.ecoledirecte.com/v3/Eleves/{}/cahierdetexte.awp?verbe=get&'.format(self.id), """data={}"token":"{}"{}""".format("{", self.token, "}"))
if connection.json()['code'] != 200:
print("error ! bad username or password")
else:
# self.token = connection.json()['token']
return connection.json()['data']
def getNotes(self):
"""get notes from the api"""
if self.token is None or self.id is None:
print("Error connection must be acitvate")
return
connection = self.__req('https://api.ecoledirecte.com/v3/eleves/{}/notes.awp?verbe=get&'.format(self.id), """data={}"token":"{}"{}""".format("{", self.token, "}"))
if connection.json()['code'] != 200:
print("error ! bad username or password")
else:
# self.token = connection.json()['token']
return connection.json()['data']
def getSL(self):
"""get sochlar life from the API"""
if self.token is None or self.id is None:
print("Error connection must be acitvate")
return
connection = self.__req('https://api.ecoledirecte.com/v3/eleves/{}/viescolaire.awp?verbe=get&='.format(self.id), """data={}"token":"{}"{}""".format("{", self.token, "}"))
if connection.json()['code'] != 200:
print("error ! bad username or password")
else:
# self.token = connection.json()['token']
return connection.json()['data']
def getCloud(self):
"""get the cloud from the API"""
if self.token is None or self.id is None:
print("Error connection must be acitvate")
return
connection = self.__req('https://api.ecoledirecte.com/v3/cloud/E/{}.awp?verbe=get&='.format(self.id), """data={}"token":"{}"{}""".format("{", self.token, "}"))
if connection.json()['code'] != 200:
print("error ! bad username or password")
else:
# self.token = connection.json()['token']
return connection.json()['data']