forked from elnigno/aula-dk-picture-download
-
Notifications
You must be signed in to change notification settings - Fork 0
/
aulaclient.py
93 lines (76 loc) · 2.97 KB
/
aulaclient.py
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
# aulaclient.py
import requests
class AulaClient:
baseUrl = 'https://www.aula.dk/api/v15/'
defaultLimit = 10
def __init__(self, cookies):
self.session = requests.Session()
self.session.cookies = cookies
def getProfiles(self):
params = {
'method': 'profiles.getProfilesByLogin'
}
response_profile = self.__sendRequest(params)
return response_profile['data']['profiles']
def getThreads(self, customParams = {}):
defaultParams = {
'sortOn': 'date',
'orderDirection': 'desc',
'page': 0
}
params = self.__mergeParams(defaultParams, customParams, 'messaging.getThreads')
response = self.__sendRequest(params)
return response['data']
def getMessagesForThread(self, threadId, customParams = {}):
defaultParams = {
'threadId': threadId,
'page': 0
}
params = self.__mergeParams(defaultParams, customParams, 'messaging.getMessagesForThread')
response = self.__sendRequest(params)
return response['data']
def getPosts(self, institutionProfileIds, customParams = {}):
defaultParams = {
'parent': 'profile',
'index': 0,
'limit': self.defaultLimit,
'isUnread': False,
'isImportant': False,
#'creatorPortalRole': '', # guardian, employee
'ownPost': False,
'institutionProfileIds[]': institutionProfileIds
}
params = self.__mergeParams(defaultParams, customParams, 'posts.getAllPosts')
response = self.__sendRequest(params)
return response['data']['posts']
def getAlbums(self, institutionProfileIds, customParams = {}):
defaultParams = {
'index': 0,
'limit': self.defaultLimit,
'sortOn': 'createdAt',
'orderDirection': 'desc',
'filterBy': 'all',
'filterInstProfileIds[]': institutionProfileIds
}
params = self.__mergeParams(defaultParams, customParams, 'gallery.getAlbums')
response = self.__sendRequest(params)
return response['data']
def getPictures(self, institutionProfileIds, albumId, customParams = {}):
defaultParams = {
'albumId': albumId,
'index': 0,
'limit': self.defaultLimit,
'sortOn': 'uploadedAt',
'orderDirection': 'desc',
'filterBy': 'all',
'filterInstProfileIds[]': institutionProfileIds
}
params = self.__mergeParams(defaultParams, customParams, 'gallery.getMedia')
response = self.__sendRequest(params)
return response['data']['results']
def __sendRequest(self, params):
return self.session.get(self.baseUrl, params=params).json()
def __mergeParams(self, defaultParams, customParams, method):
params = defaultParams | customParams
params['method'] = method
return params