【问题标题】:Export Csv Output file to Desktop in Rundeck在 Rundeck 中将 Csv 输出文件导出到桌面
【发布时间】:2021-01-06 10:29:30
【问题描述】:

我正在调用 API URL 并将输出存储在 Csv 文件中,如下所示,由于 URL 在服务器上运行,它将 csv 文件存储在服务器中,我希望在 Rundeck 中运行时将其下载到桌面本地

代码:

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) + '\n')

而且 Csv 中的数据在一行中,我希望这一行低于另一行。

CSV 截图:

在 Csv 中预期:

请帮忙,谢谢

【问题讨论】:

    标签: api csv rundeck


    【解决方案1】:

    您可以创建最后一步,使用 python 代码将文件放在桌面路径上,查看this

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-12-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-01-17
      • 2015-05-25
      • 2016-09-14
      • 1970-01-01
      相关资源
      最近更新 更多