-
Notifications
You must be signed in to change notification settings - Fork 2
/
1.py
105 lines (96 loc) · 4.24 KB
/
1.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
94
95
96
97
98
99
100
101
102
103
104
105
# -*- coding: UTF-8 -*-
import requests as req
import json, sys, time, random
import argparse
import os
import pytz
from datetime import datetime
# import parser
#先注册azure应用,确保应用有以下权限:
#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
# 注册后一定要再点代表xxx授予管理员同意,否则outlook api无法调用
# parser = argparse.ArgumentParser()
# parser.add_argument('--config_id', required=True)
# parser.add_argument('--config_key', required=True)
# args=parser.parse_args()
# id=args.config_id
# secret=args.config_key
path=sys.path[0]+r'/1.txt'
num1 = 0
# get the timezone for China Standard Time (CST)
cst = pytz.timezone('Asia/Shanghai')
# get the current time in the CST timezone
now = datetime.now(cst)
# format the time as a string
localtime = now.strftime("%Y-%m-%d %H:%M:%S")
def gettoken(refresh_token):
headers={'Content-Type':'application/x-www-form-urlencoded'
}
data={'grant_type': 'refresh_token',
'refresh_token': refresh_token,
'client_id':id,
'client_secret':secret,
'redirect_uri':'http://localhost:53682/'
}
html = req.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():
fo = open(path, "r+")
refresh_token = fo.read()
fo.close()
global num1
# localtime = time.asctime( time.localtime(time.time()) )
access_token=gettoken(refresh_token)
headers={
'Authorization':access_token,
'Content-Type':'application/json'
}
print('此次运行开始时间为 :', localtime)
with open(sys.path[0]+r'/time.log','a',encoding="utf-8") as fd:
fd.write('运行开始时间为: %s \n' % localtime)
try:
if req.get(r'https://graph.microsoft.com/v1.0/me/drive/root',headers=headers).status_code == 200:
num1+=1
print("1调用成功"+str(num1)+'次')
if req.get(r'https://graph.microsoft.com/v1.0/me/drive',headers=headers).status_code == 200:
num1+=1
print("2调用成功"+str(num1)+'次')
if req.get(r'https://graph.microsoft.com/v1.0/drive/root',headers=headers).status_code == 200:
num1+=1
print('3调用成功'+str(num1)+'次')
if req.get(r'https://graph.microsoft.com/v1.0/users',headers=headers).status_code == 200:
num1+=1
print('4调用成功'+str(num1)+'次')
if req.get(r'https://graph.microsoft.com/v1.0/me/messages',headers=headers).status_code == 200:
num1+=1
print('5调用成功'+str(num1)+'次')
if req.get(r'https://graph.microsoft.com/v1.0/me/mailFolders/inbox/messageRules',headers=headers).status_code == 200:
num1+=1
print('6调用成功'+str(num1)+'次')
if req.get(r'https://graph.microsoft.com/v1.0/me/mailFolders/inbox/messageRules',headers=headers).status_code == 200:
num1+=1
print('7调用成功'+str(num1)+'次')
if req.get(r'https://graph.microsoft.com/v1.0/me/drive/root/children',headers=headers).status_code == 200:
num1+=1
print('8调用成功'+str(num1)+'次')
if req.get(r'https://api.powerbi.com/v1.0/myorg/apps',headers=headers).status_code == 200:
num1+=1
print('8调用成功'+str(num1)+'次')
if req.get(r'https://graph.microsoft.com/v1.0/me/mailFolders',headers=headers).status_code == 200:
num1+=1
print('9调用成功'+str(num1)+'次')
if req.get(r'https://graph.microsoft.com/v1.0/me/outlook/masterCategories',headers=headers).status_code == 200:
num1+=1
print('10调用成功'+str(num1)+'次')
except:
print("pass")
pass
for _ in range(6):
main()
for i in range(random.randint(30, 60),0,-1):
time.sleep(1)