Last active
May 1, 2021 19:08
-
-
Save kuharan/20647cdd0dff349693341ae4b4a64295 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def get_dp_info(session, access_token, incident): | |
url = DP_BASE_URL + 'idb/sessions/filter/' | |
# transform session name format | |
zeros_to_prefix = 4 - len(incident['session_name'].split('-')[-1]) | |
session_name = incident['session_name'].replace('-', ' ' + zeros_to_prefix * '0') | |
payload = json.dumps({ | |
"filter": { | |
"sessionType": [0], | |
"datalist": incident['specification'], | |
"name": session_name | |
} | |
}) | |
headers = { | |
'Authorization': 'Bearer {}'.format(access_token), | |
'Content-Type': 'application/json' | |
} | |
response = session.post(url, headers=headers, data=payload) | |
if len(json.loads(response.text)['items'])>0: | |
incident['sessionType'] = json.loads(response.text)['items'][0]['sessionType'] | |
incident['status'] = json.loads(response.text)['items'][0]['status'] | |
incident['backupType'] = json.loads(response.text)['items'][0]['backupType'] | |
incident['endTime'] = json.loads(response.text)['items'][0]['endTime'] | |
return incident | |
else: | |
print('cant find dp session record for ', incident['session_name']) | |
#call this using | |
final_list = [] | |
for incident in snow_data: | |
inc = get_dp_info(session, access_token, incident) | |
final_list.append(inc) | |
#discarding the ones which are empty | |
final_list = [i for i in final_list if i] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment