-
Notifications
You must be signed in to change notification settings - Fork 4
/
main.py
81 lines (69 loc) · 3.02 KB
/
main.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
import requests
import json
import time
import random
# Register the azure app first and make sure the app has the following permissions:
# files: Files.Read.All、Files.ReadWrite.All、Sites.Read.All、Sites.ReadWrite.All
# user: User.Read.All、User.ReadWrite.All、Directory.Read.All、Directory.ReadWrite.All
# mail: Mail.Read、Mail.ReadWrite、MailboxSettings.Read、MailboxSettings.ReadWrite
# After registration, you must click on behalf of xxx to grant administrator consent, otherwise outlook api cannot be called
calls = [
'https://graph.microsoft.com/v1.0/me/drive/root',
'https://graph.microsoft.com/v1.0/me/drive',
'https://graph.microsoft.com/v1.0/drive/root',
'https://graph.microsoft.com/v1.0/users',
'https://graph.microsoft.com/v1.0/me/messages',
'https://graph.microsoft.com/v1.0/me/mailFolders/inbox/messageRules',
'https://graph.microsoft.com/v1.0/me/drive/root/children',
'https://api.powerbi.com/v1.0/myorg/apps',
'https://graph.microsoft.com/v1.0/me/mailFolders',
'https://graph.microsoft.com/v1.0/me/outlook/masterCategories',
'https://graph.microsoft.com/v1.0/applications?$count=true',
'https://graph.microsoft.com/v1.0/me/?$select=displayName,skills',
'https://graph.microsoft.com/v1.0/me/mailFolders/Inbox/messages/delta',
'https://graph.microsoft.com/beta/me/outlook/masterCategories',
'https://graph.microsoft.com/beta/me/messages?$select=internetMessageHeaders&$top=1',
'https://graph.microsoft.com/v1.0/sites/root/lists',
'https://graph.microsoft.com/v1.0/sites/root',
'https://graph.microsoft.com/v1.0/sites/root/drives'
]
def get_access_token(refresh_token, client_id, client_secret):
headers = {
'Content-Type': 'application/x-www-form-urlencoded'
}
data = {
'grant_type': 'refresh_token',
'refresh_token': refresh_token,
'client_id': client_id,
'client_secret': client_secret,
'redirect_uri': 'http://localhost:53682/'
}
html = requests.post('https://login.microsoftonline.com/common/oauth2/v2.0/token', data=data, headers=headers)
jsontxt = json.loads(html.text)
refresh_token = jsontxt['refresh_token']
access_token = jsontxt['access_token']
return access_token
def main():
random.shuffle(calls)
endpoints = calls[random.randint(0,10)::]
access_token = get_access_token(refresh_token, client_id, client_secret)
session = requests.Session()
session.headers.update({
'Authorization': access_token,
'Content-Type': 'application/json'
})
num = 0
for endpoint in endpoints:
try:
response = session.get(endpoint)
if response.status_code == 200:
num += 1
print(f'{num}th Call successful')
except requests.exceptions.RequestException as e:
print(e)
pass
localtime = time.asctime(time.localtime(time.time()))
print('The end of this run is :', localtime)
print('Number of calls is :', str(len(endpoints)))
for _ in range(3):
main()