-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPage_Views.py
More file actions
36 lines (28 loc) · 1020 Bytes
/
Page_Views.py
File metadata and controls
36 lines (28 loc) · 1020 Bytes
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
import requests
import json
key = "Bearer " #### Add API Key After Bearer
domain = "" #### Add domain into quotes Example: https://HackerPanda.instructure.com
user_id = "" ### Canvas User Id
start = "" ### Start Time in UTC Time example 2021-04-20T00:00:00Z
end = "" ### End Time in UTC Time
############## Do not change #################
headers = {
'Authorization': key
}
data_set = []
next_check = 'default'
r = requests.get(domain + "/api/v1/users/" + user_id + "/page_views?start_time=" + start + "&end_time=" + end + "&per_page=100", headers=headers)
next_ = r.links['next']['url']
d = r.json()
data_set.append(d)
while next_check != 'null':
r = requests.get(next_, headers=headers)
next_d = r.json()
data_set.append(next_d)
next_check = r.links.get('next', 'null')
if next_check != 'null':
next_ = r.links['next']['url']
#print(json.dumps(data_set, indent=4))
file = open("requests.txt", "w")
file.write(json.dumps(data_set, indent=4))
file.close()