-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupdate_token.py
39 lines (30 loc) · 903 Bytes
/
update_token.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
import requests
import json
import os
import time
f = open('json/Token_amo.json')
token_amo = json.load(f)
f.close()
def update_token_amo(token_json):
domain = os.environ.get('DOMAIN')
url = 'https://' + domain + '/oauth2/access_token'
f = open('json/client_ids.json')
client_ids = json.load(f)
f.close()
headers = {
'Content-Type': 'application/json'
}
body = {
'client_id': client_ids['client_id'],
'client_secret': client_ids['client_secret'],
'grant_type': client_ids['grant_type'],
'refresh_token': token_json['refresh_token'],
'redirect_uri': client_ids['redirect_uri']
}
response = requests.post(url=url, json=body, headers=headers)
f = open('json/Token_amo.json', 'w')
f.write(response.text)
f.close()
while True:
update_token_amo(token_amo)
time.sleep(token_amo['expires_in'])