-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathzoho_bootstrap.py
More file actions
35 lines (30 loc) · 1.25 KB
/
zoho_bootstrap.py
File metadata and controls
35 lines (30 loc) · 1.25 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
from zoho_oauth import generateAuthUrl, getAccessToken, refreshAccessToken
from zoho_client import ZohoClient
import pickle
store = {}
def refreshAccessTokenFunc():
global store
access_token_res = refreshAccessToken(store['refresh_token'])
store['access_token'] = access_token_res["access_token"]
pickle.dump(store, open("zoho_tokens.pkl", "wb"))
return store['access_token']
try:
store = pickle.load(open("zoho_tokens.pkl", "rb"))
except (OSError, IOError) as e:
pickle.dump(store, open("zoho_tokens.pkl", "wb"))
if 'access_token' not in store or 'refresh_token' not in store:
print(generateAuthUrl())
code = input("Enter code: ")
access_token_res = getAccessToken(code)
print(access_token_res)
store['refresh_token'] = access_token_res["refresh_token"]
store['access_token'] = access_token_res["access_token"]
pickle.dump(store, open("zoho_tokens.pkl", "wb"))
zc = ZohoClient(store['access_token'], refreshAccessTokenFunc)
# emails = zc.getEmails()
# content = []
# for email in emails:
# email.update(zc.readEmailContent(email))
# print(email)
# print(zc.replyEmail(email, {'subject': 'test reply', 'content': 'test content\n'},
# schedule={'isSchedule': True, 'scheduleType': 5}))