-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathfunctions.py
More file actions
62 lines (47 loc) · 1.73 KB
/
Copy pathfunctions.py
File metadata and controls
62 lines (47 loc) · 1.73 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
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
import requests
import json
from datetime import datetime
from dotenv import load_dotenv
import os
import pytz
load_dotenv()
# Load env variables
user = os.environ.get('user')
password = os.environ.get('password')
workspaceId = os.environ.get('workspaceId')
modelId = os.environ.get('modelId')
processId = os.environ.get('processId')
fileId = os.environ.get('fileId')
timezone = os.environ.get('timezone')
def get_auth_token(user, password):
url = 'https://auth.anaplan.com/token/authenticate'
response = requests.request("POST", url, auth=(user, password))
return response.json()['tokenInfo']['tokenValue']
anaplan_auth_token = get_auth_token(user, password)
headers = {
'Authorization': f'AnaplanAuthToken {anaplan_auth_token}',
'Content-Type': 'application/json'
}
timestamp = datetime.now(pytz.timezone(timezone)).strftime('%d/%m/%Y-%H:%M:%S')
textstring = f'LatestDateTime,{timestamp}'
def update_file():
url = f'https://api.anaplan.com/2/0/workspaces/{workspaceId}/models/{modelId}/files/{fileId}'
headers = {
'Authorization': f'AnaplanAuthToken {anaplan_auth_token}',
'Content-Type': 'application/octet-stream'
}
response = requests.request('PUT', url, data=textstring, headers=headers)
return response
def run_process():
url = f'https://api.anaplan.com/2/0/workspaces/{workspaceId}/models/{modelId}/processes/{processId}/tasks'
payload = json.dumps({'localeName': 'en_US'})
response = requests.request('POST', url, headers=headers, data=payload)
return response
def logout():
url = 'https://auth.anaplan.com/token/logout'
response = requests.request("POST", url, headers=headers)
return response
def update_time():
update_file()
run_process()
logout()