-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathworkato.py
208 lines (173 loc) · 7.2 KB
/
workato.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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
import random
import pandas as pd
import requests
from datetime import datetime, timedelta
def getWorkatoRecipe(self) -> str:
"""
Retrieving the list of Workato recipes
This function generates JSON data containing details for Workato recipes, structured as follows:
id: recipe id
description: recipe description
successful_job_count: successful job count
last_status_success: last success status
last_status_cancelled: last cancelled status
last_status_datetime: last status datetime
last_status_text: last status text
last_description: last description
last_master_job_id: last master job id
last_repeat_job_id: last repeat job id
action_count: task usage
active: active status
folder_id: folder id
Returns:
string: Data in JSON format.
Example:
>>> getWorkatoRecipe()
[
{
'id': 1096317,
'description': 'Recipe A',
'successful_job_count': 5825,
'failed_job_count': 93,
'last_status_success': True,
'last_status_cancelled': False,
'last_status_datetime': '2023-11-27T19:30:07.000+08:00',
'last_status_text': 'Last job: Successful',
'last_description': '',
'last_master_job_id': 'j-AKPozrbX-F4YXJ8',
'last_repeat_job_id': 'j-AKPozrbX-F4YXJ8',
'action_count': 41645,
'active': True,
'folder_id': 141423
},
{
'id': 1096318,
'description': 'Recipe B',
'successful_job_count': 5825,
'failed_job_count': 93,
'last_status_success': True,
'last_status_cancelled': False,
'last_status_datetime': '2023-11-27T19:30:07.000+08:00',
'last_status_text': 'Last job: Successful',
'last_description': '',
'last_master_job_id': 'j-AKPozrgX-p8ktMQ',
'last_repeat_job_id': 'j-AKPozrgX-p8ktMQ',
'action_count': 50974,
'active': True,
'folder_id': 141423
}
] # This is an example output and may vary each time the function is called.
"""
print('-executing function--')
''' get_sign_session '''
options = {
'method': 'GET',
'url': 'https://app.workato.com/web_api/auth_user.json',
'headers': {
'Host': 'app.workato.com',
'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:105.0) Gecko/20100101 Firefox/105.0',
'Accept': 'application/json, text/plain, */*',
'Accept-Language': 'en-US,en;q=0.5',
'Referer': 'https://app.workato.com/users/sign_in',
'Content-Type': 'application/json',
'Connection': 'keep-alive',
'Sec-Fetch-Dest': 'empty',
'Sec-Fetch-Mode': 'cors',
'Sec-Fetch-Site': 'same-origin'
}
}
response = requests.request(options['method'], options['url'], headers=options['headers'])
if response.status_code != 200:
raise Exception(f"Failed to get sign session: {response.status_code}")
raw_cookies = response.headers['set-cookie']
xsrf_token = ''
workato_app_session = ''
for cookie in raw_cookies.split(';'):
cookie = cookie.strip()
if cookie.startswith('XSRF-TOKEN'):
xsrf_token = cookie.split('=')[1]
elif cookie.startswith('secure, _workato_app_session'):
workato_app_session = cookie.split('=')[1]
print('xsrf_token:', xsrf_token)
print('workato_app_session:', workato_app_session)
''' end of get_sign_session '''
''' get_session '''
x_csrf_token_ = requests.utils.unquote(xsrf_token.replace('+', ' '))
workato_app_session_ = workato_app_session
print('xsrf_token:', x_csrf_token_)
print('workato_app_session:', workato_app_session_)
options = {
'method': 'POST',
'url': 'https://app.workato.com/users/sign_in.json',
'headers': {
'Host': 'app.workato.com',
'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:105.0) Gecko/20100101 Firefox/105.0',
'Accept': 'application/json, text/plain, */*',
'Accept-Language': 'en-US,en;q=0.5',
'Referer': 'https://app.workato.com/users/sign_in',
'X-CSRF-TOKEN': x_csrf_token_,
'X-Requested-With': 'XMLHttpRequest',
'Content-Type': 'application/json',
'Origin': 'https://app.workato.com',
'Connection': 'keep-alive',
'Cookie': f'_workato_app_session={workato_app_session_}',
'Sec-Fetch-Dest': 'empty',
'Sec-Fetch-Mode': 'cors',
'Sec-Fetch-Site': 'same-origin'
},
'json': {
'user': {
'email': '',
'password': ''
}
}
}
response = requests.request(options['method'], options['url'], headers=options['headers'], json=options['json'])
if response.status_code != 200:
raise Exception(f"Failed to get session: {response.status_code}")
raw_cookies = response.headers['set-cookie']
xsrf_token2 = ''
workato_app_session2 = ''
for cookie in raw_cookies.split(';'):
cookie = cookie.strip()
#print(cookie)
if cookie.startswith('secure, XSRF-TOKEN'):
xsrf_token2 = cookie.split('=')[1]
elif cookie.startswith('secure, _workato_app_session'):
workato_app_session2 = cookie.split('=')[1]
print('xsrf_token2:', xsrf_token2)
print('workato_app_session2:', workato_app_session2)
''' end of get_session '''
# Get the current date and time
date = datetime.now()
# Format the current date and time
today = date.strftime("%Y-%m-%dT%H:%M:%S%z")
# Calculate one month ago from the current date
one_month_ago = date - timedelta(days=30)
# Format one month ago
one_month_ago_formatted = one_month_ago.strftime("%Y-%m-%dT%H:%M:%S%z")
options = {
'method': 'GET',
'url': f"https://app.workato.com/dashboard/flows.json?started_at_from={one_month_ago_formatted}&started_at_to={today}&sort_term=failed_job_count&sort_direction=asc&recipe_type=active&folder_id=450562",
'headers': {
'Host': 'app.workato.com',
'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:105.0) Gecko/20100101 Firefox/105.0',
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8',
'Accept-Language': 'en-US,en;q=0.5',
'Connection': 'keep-alive',
'Cookie': f'XSRF-TOKEN={xsrf_token2}; _workato_app_session={workato_app_session2};',
'Upgrade-Insecure-Requests': '1',
'Sec-Fetch-Dest': 'document',
'Sec-Fetch-Mode': 'navigate',
'Sec-Fetch-Site': 'none',
'Sec-Fetch-User': '?1'
}
}
response = requests.request(options['method'], options['url'], headers=options['headers'])
body = response.json()
df = pd.DataFrame(body['result']['flows'])
print(df)
symbol_txt = df.to_string(index=None)
return f"""
{symbol_txt}
""".strip()