I am calling a API URL and storing the output in Csv file as below, since URL is run on a server, it stores the csv file in Server, i want this to be downloaded locally in Desktop when run in Rundeck
Code:
import re
import json
import warnings
import urllib.request
import csv
warnings.filterwarnings('ignore', message='Unverified HTTPS request')
url = "http://lappmachine.server:4450/api/35/project/ProjectName01/executions"
headers = {
'Accept': 'application/json',
'X-Rundeck-Auth-Token': '#Tokens here#'
}
response = requests.request("GET", url, headers=headers, verify = False)
#print(response.text.encode('utf8'))
response_value = response.json()
response_value = json.dumps(response_value)
resp = json.loads(response_value)
with open('execute.csv','w') as executeData:
i = resp['executions']
res_list = []
with open('ExecOutput.csv','w') as writer:
for a in i:
try:
if (a['id']==0):
print("Is empty")
res_list.append('')
else:
print("Job ID is : " + str(a['id']))
res_list.append(str(a['id']))
except KeyError:
print("Job ID: Key error issue, Check input again")
try:
if(a['project']==0):
print("Project data not available")
res_list.append('')
else:
print("Project Name: "+a['project'])
res_list.append(str(a['project']))
except KeyError:
print("Project Name: Key error issue, Check input again")
try:
if(a['name']):
print("Job Name not available")
res_list.append('')
else:
print("JobName: "+a['name'])
res_list.append(str(str(a['name'])))
except KeyError:
print("JobName: key Error check again")
writer.write(','.join(res_list) + '
')
And the data in Csv comes in a single line, i would want this one below the other.
Csv Screenshot:
Expected in Csv:
kindly help, Thanks
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…